<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="author" content="Safari Books Online">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="apple-itunes-app" content="app-id=881697395, app-argument=safaridetail://9781430261933">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=1.0">
    <meta property="twitter:account_id" content="4503599627559754">
    <script type="text/javascript" src="https://bam.nr-data.net/1/510f1a6865?a=3275661&amp;v=1016.8b58850&amp;to=YgdaZ0NSW0cEB0RdWltNfkZfUEFdCgofXFBHDVYdR1pQQxZeRl1QQj1aWkU%3D&amp;rst=4413&amp;ref=https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml&amp;ap=620&amp;be=906&amp;fe=3495&amp;dc=1448&amp;af=err,xhr,stn,ins&amp;perf=%7B%22timing%22:%7B%22of%22:1485238464449,%22n%22:0,%22u%22:892,%22ue%22:892,%22f%22:1,%22dn%22:1,%22dne%22:1,%22c%22:1,%22ce%22:1,%22rq%22:3,%22rp%22:886,%22rpe%22:891,%22dl%22:901,%22di%22:2354,%22ds%22:2354,%22de%22:2529,%22dc%22:4402,%22l%22:4402,%22le%22:4403%7D,%22navigation%22:%7B%7D%7D&amp;jsonp=NREUM.setToken"></script>
    <script src="https://js-agent.newrelic.com/nr-1016.min.js"></script>
    <script type="text/javascript" async="" src="https://www.google-analytics.com/plugins/ua/linkid.js"></script>
    <script async="" src="//www.google-analytics.com/analytics.js"></script>
    <script type="text/javascript">
    (window.NREUM || (NREUM = {})).loader_config = {
        xpid: "VQQDUVVVGwACU1RUAQA="
    };
    window.NREUM || (NREUM = {}), __nr_require = function(t, e, n) {
        function r(n) {
            if (!e[n]) {
                var o = e[n] = {
                    exports: {}
                };
                t[n][0].call(o.exports, function(e) {
                    var o = t[n][1][e];
                    return r(o || e)
                }, o, o.exports)
            }
            return e[n].exports
        }
        if ("function" == typeof __nr_require) return __nr_require;
        for (var o = 0; o < n.length; o++) r(n[o]);
        return r
    }({
        1: [function(t, e, n) {
            function r(t) {
                try {
                    c.console && console.log(t)
                } catch (e) {}
            }
            var o, i = t("ee"),
                a = t(15),
                c = {};
            try {
                o = localStorage.getItem("__nr_flags").split(","), console && "function" == typeof console.log && (c.console = !0, o.indexOf("dev") !== -1 && (c.dev = !0), o.indexOf("nr_dev") !== -1 && (c.nrDev = !0))
            } catch (s) {}
            c.nrDev && i.on("internal-error", function(t) {
                r(t.stack)
            }), c.dev && i.on("fn-err", function(t, e, n) {
                r(n.stack)
            }), c.dev && (r("NR AGENT IN DEVELOPMENT MODE"), r("flags: " + a(c, function(t, e) {
                return t
            }).join(", ")))
        }, {}],
        2: [function(t, e, n) {
            function r(t, e, n, r, o) {
                try {
                    d ? d -= 1 : i("err", [o || new UncaughtException(t, e, n)])
                } catch (c) {
                    try {
                        i("ierr", [c, (new Date).getTime(), !0])
                    } catch (s) {}
                }
                return "function" == typeof f && f.apply(this, a(arguments))
            }

            function UncaughtException(t, e, n) {
                this.message = t || "Uncaught error with no additional information", this.sourceURL = e, this.line = n
            }

            function o(t) {
                i("err", [t, (new Date).getTime()])
            }
            var i = t("handle"),
                a = t(16),
                c = t("ee"),
                s = t("loader"),
                f = window.onerror,
                u = !1,
                d = 0;
            s.features.err = !0, t(1), window.onerror = r;
            try {
                throw new Error
            } catch (l) {
                "stack" in l && (t(8), t(7), "addEventListener" in window && t(5), s.xhrWrappable && t(9), u = !0)
            }
            c.on("fn-start", function(t, e, n) {
                u && (d += 1)
            }), c.on("fn-err", function(t, e, n) {
                u && (this.thrown = !0, o(n))
            }), c.on("fn-end", function() {
                u && !this.thrown && d > 0 && (d -= 1)
            }), c.on("internal-error", function(t) {
                i("ierr", [t, (new Date).getTime(), !0])
            })
        }, {}],
        3: [function(t, e, n) {
            t("loader").features.ins = !0
        }, {}],
        4: [function(t, e, n) {
            function r(t) {}
            if (window.performance && window.performance.timing && window.performance.getEntriesByType) {
                var o = t("ee"),
                    i = t("handle"),
                    a = t(8),
                    c = t(7),
                    s = "learResourceTimings",
                    f = "addEventListener",
                    u = "resourcetimingbufferfull",
                    d = "bstResource",
                    l = "resource",
                    p = "-start",
                    h = "-end",
                    m = "fn" + p,
                    w = "fn" + h,
                    v = "bstTimer",
                    y = "pushState";
                t("loader").features.stn = !0, t(6);
                var g = NREUM.o.EV;
                o.on(m, function(t, e) {
                    var n = t[0];
                    n instanceof g && (this.bstStart = Date.now())
                }), o.on(w, function(t, e) {
                    var n = t[0];
                    n instanceof g && i("bst", [n, e, this.bstStart, Date.now()])
                }), a.on(m, function(t, e, n) {
                    this.bstStart = Date.now(), this.bstType = n
                }), a.on(w, function(t, e) {
                    i(v, [e, this.bstStart, Date.now(), this.bstType])
                }), c.on(m, function() {
                    this.bstStart = Date.now()
                }), c.on(w, function(t, e) {
                    i(v, [e, this.bstStart, Date.now(), "requestAnimationFrame"])
                }), o.on(y + p, function(t) {
                    this.time = Date.now(), this.startPath = location.pathname + location.hash
                }), o.on(y + h, function(t) {
                    i("bstHist", [location.pathname + location.hash, this.startPath, this.time])
                }), f in window.performance && (window.performance["c" + s] ? window.performance[f](u, function(t) {
                    i(d, [window.performance.getEntriesByType(l)]), window.performance["c" + s]()
                }, !1) : window.performance[f]("webkit" + u, function(t) {
                    i(d, [window.performance.getEntriesByType(l)]), window.performance["webkitC" + s]()
                }, !1)), document[f]("scroll", r, {
                    passive: !0
                }), document[f]("keypress", r, !1), document[f]("click", r, !1)
            }
        }, {}],
        5: [function(t, e, n) {
            function r(t) {
                for (var e = t; e && !e.hasOwnProperty(u);) e = Object.getPrototypeOf(e);
                e && o(e)
            }

            function o(t) {
                c.inPlace(t, [u, d], "-", i)
            }

            function i(t, e) {
                return t[1]
            }
            var a = t("ee").get("events"),
                c = t(17)(a, !0),
                s = t("gos"),
                f = XMLHttpRequest,
                u = "addEventListener",
                d = "removeEventListener";
            e.exports = a, "getPrototypeOf" in Object ? (r(document), r(window), r(f.prototype)) : f.prototype.hasOwnProperty(u) && (o(window), o(f.prototype)), a.on(u + "-start", function(t, e) {
                var n = t[1],
                    r = s(n, "nr@wrapped", function() {
                        function t() {
                            if ("function" == typeof n.handleEvent) return n.handleEvent.apply(n, arguments)
                        }
                        var e = {
                            object: t,
                            "function": n
                        }[typeof n];
                        return e ? c(e, "fn-", null, e.name || "anonymous") : n
                    });
                this.wrapped = t[1] = r
            }), a.on(d + "-start", function(t) {
                t[1] = this.wrapped || t[1]
            })
        }, {}],
        6: [function(t, e, n) {
            var r = t("ee").get("history"),
                o = t(17)(r);
            e.exports = r, o.inPlace(window.history, ["pushState", "replaceState"], "-")
        }, {}],
        7: [function(t, e, n) {
            var r = t("ee").get("raf"),
                o = t(17)(r),
                i = "equestAnimationFrame";
            e.exports = r, o.inPlace(window, ["r" + i, "mozR" + i, "webkitR" + i, "msR" + i], "raf-"), r.on("raf-start", function(t) {
                t[0] = o(t[0], "fn-")
            })
        }, {}],
        8: [function(t, e, n) {
            function r(t, e, n) {
                t[0] = a(t[0], "fn-", null, n)
            }

            function o(t, e, n) {
                this.method = n, this.timerDuration = "number" == typeof t[1] ? t[1] : 0, t[0] = a(t[0], "fn-", this, n)
            }
            var i = t("ee").get("timer"),
                a = t(17)(i),
                c = "setTimeout",
                s = "setInterval",
                f = "clearTimeout",
                u = "-start",
                d = "-";
            e.exports = i, a.inPlace(window, [c, "setImmediate"], c + d), a.inPlace(window, [s], s + d), a.inPlace(window, [f, "clearImmediate"], f + d), i.on(s + u, r), i.on(c + u, o)
        }, {}],
        9: [function(t, e, n) {
            function r(t, e) {
                d.inPlace(e, ["onreadystatechange"], "fn-", c)
            }

            function o() {
                var t = this,
                    e = u.context(t);
                t.readyState > 3 && !e.resolved && (e.resolved = !0, u.emit("xhr-resolved", [], t)), d.inPlace(t, w, "fn-", c)
            }

            function i(t) {
                v.push(t), h && (g = -g, b.data = g)
            }

            function a() {
                for (var t = 0; t < v.length; t++) r([], v[t]);
                v.length && (v = [])
            }

            function c(t, e) {
                return e
            }

            function s(t, e) {
                for (var n in t) e[n] = t[n];
                return e
            }
            t(5);
            var f = t("ee"),
                u = f.get("xhr"),
                d = t(17)(u),
                l = NREUM.o,
                p = l.XHR,
                h = l.MO,
                m = "readystatechange",
                w = ["onload", "onerror", "onabort", "onloadstart", "onloadend", "onprogress", "ontimeout"],
                v = [];
            e.exports = u;
            var y = window.XMLHttpRequest = function(t) {
                var e = new p(t);
                try {
                    u.emit("new-xhr", [e], e), e.addEventListener(m, o, !1)
                } catch (n) {
                    try {
                        u.emit("internal-error", [n])
                    } catch (r) {}
                }
                return e
            };
            if (s(p, y), y.prototype = p.prototype, d.inPlace(y.prototype, ["open", "send"], "-xhr-", c), u.on("send-xhr-start", function(t, e) {
                    r(t, e), i(e)
                }), u.on("open-xhr-start", r), h) {
                var g = 1,
                    b = document.createTextNode(g);
                new h(a).observe(b, {
                    characterData: !0
                })
            } else f.on("fn-end", function(t) {
                t[0] && t[0].type === m || a()
            })
        }, {}],
        10: [function(t, e, n) {
            function r(t) {
                var e = this.params,
                    n = this.metrics;
                if (!this.ended) {
                    this.ended = !0;
                    for (var r = 0; r < d; r++) t.removeEventListener(u[r], this.listener, !1);
                    if (!e.aborted) {
                        if (n.duration = (new Date).getTime() - this.startTime, 4 === t.readyState) {
                            e.status = t.status;
                            var i = o(t, this.lastSize);
                            if (i && (n.rxSize = i), this.sameOrigin) {
                                var a = t.getResponseHeader("X-NewRelic-App-Data");
                                a && (e.cat = a.split(", ").pop())
                            }
                        } else e.status = 0;
                        n.cbTime = this.cbTime, f.emit("xhr-done", [t], t), c("xhr", [e, n, this.startTime])
                    }
                }
            }

            function o(t, e) {
                var n = t.responseType;
                if ("json" === n && null !== e) return e;
                var r = "arraybuffer" === n || "blob" === n || "json" === n ? t.response : t.responseText;
                return h(r)
            }

            function i(t, e) {
                var n = s(e),
                    r = t.params;
                r.host = n.hostname + ":" + n.port, r.pathname = n.pathname, t.sameOrigin = n.sameOrigin
            }
            var a = t("loader");
            if (a.xhrWrappable) {
                var c = t("handle"),
                    s = t(11),
                    f = t("ee"),
                    u = ["load", "error", "abort", "timeout"],
                    d = u.length,
                    l = t("id"),
                    p = t(14),
                    h = t(13),
                    m = window.XMLHttpRequest;
                a.features.xhr = !0, t(9), f.on("new-xhr", function(t) {
                    var e = this;
                    e.totalCbs = 0, e.called = 0, e.cbTime = 0, e.end = r, e.ended = !1, e.xhrGuids = {}, e.lastSize = null, p && (p > 34 || p < 10) || window.opera || t.addEventListener("progress", function(t) {
                        e.lastSize = t.loaded
                    }, !1)
                }), f.on("open-xhr-start", function(t) {
                    this.params = {
                        method: t[0]
                    }, i(this, t[1]), this.metrics = {}
                }), f.on("open-xhr-end", function(t, e) {
                    "loader_config" in NREUM && "xpid" in NREUM.loader_config && this.sameOrigin && e.setRequestHeader("X-NewRelic-ID", NREUM.loader_config.xpid)
                }), f.on("send-xhr-start", function(t, e) {
                    var n = this.metrics,
                        r = t[0],
                        o = this;
                    if (n && r) {
                        var i = h(r);
                        i && (n.txSize = i)
                    }
                    this.startTime = (new Date).getTime(), this.listener = function(t) {
                        try {
                            "abort" === t.type && (o.params.aborted = !0), ("load" !== t.type || o.called === o.totalCbs && (o.onloadCalled || "function" != typeof e.onload)) && o.end(e)
                        } catch (n) {
                            try {
                                f.emit("internal-error", [n])
                            } catch (r) {}
                        }
                    };
                    for (var a = 0; a < d; a++) e.addEventListener(u[a], this.listener, !1)
                }), f.on("xhr-cb-time", function(t, e, n) {
                    this.cbTime += t, e ? this.onloadCalled = !0 : this.called += 1, this.called !== this.totalCbs || !this.onloadCalled && "function" == typeof n.onload || this.end(n)
                }), f.on("xhr-load-added", function(t, e) {
                    var n = "" + l(t) + !!e;
                    this.xhrGuids && !this.xhrGuids[n] && (this.xhrGuids[n] = !0, this.totalCbs += 1)
                }), f.on("xhr-load-removed", function(t, e) {
                    var n = "" + l(t) + !!e;
                    this.xhrGuids && this.xhrGuids[n] && (delete this.xhrGuids[n], this.totalCbs -= 1)
                }), f.on("addEventListener-end", function(t, e) {
                    e instanceof m && "load" === t[0] && f.emit("xhr-load-added", [t[1], t[2]], e)
                }), f.on("removeEventListener-end", function(t, e) {
                    e instanceof m && "load" === t[0] && f.emit("xhr-load-removed", [t[1], t[2]], e)
                }), f.on("fn-start", function(t, e, n) {
                    e instanceof m && ("onload" === n && (this.onload = !0), ("load" === (t[0] && t[0].type) || this.onload) && (this.xhrCbStart = (new Date).getTime()))
                }), f.on("fn-end", function(t, e) {
                    this.xhrCbStart && f.emit("xhr-cb-time", [(new Date).getTime() - this.xhrCbStart, this.onload, e], e)
                })
            }
        }, {}],
        11: [function(t, e, n) {
            e.exports = function(t) {
                var e = document.createElement("a"),
                    n = window.location,
                    r = {};
                e.href = t, r.port = e.port;
                var o = e.href.split("://");
                !r.port && o[1] && (r.port = o[1].split("/")[0].split("@").pop().split(":")[1]), r.port && "0" !== r.port || (r.port = "https" === o[0] ? "443" : "80"), r.hostname = e.hostname || n.hostname, r.pathname = e.pathname, r.protocol = o[0], "/" !== r.pathname.charAt(0) && (r.pathname = "/" + r.pathname);
                var i = !e.protocol || ":" === e.protocol || e.protocol === n.protocol,
                    a = e.hostname === document.domain && e.port === n.port;
                return r.sameOrigin = i && (!e.hostname || a), r
            }
        }, {}],
        12: [function(t, e, n) {
            function r() {}

            function o(t, e, n) {
                return function() {
                    return i(t, [(new Date).getTime()].concat(c(arguments)), e ? null : this, n), e ? void 0 : this
                }
            }
            var i = t("handle"),
                a = t(15),
                c = t(16),
                s = t("ee").get("tracer"),
                f = NREUM;
            "undefined" == typeof window.newrelic && (newrelic = f);
            var u = ["setPageViewName", "setCustomAttribute", "setErrorHandler", "finished", "addToTrace", "inlineHit", "addRelease"],
                d = "api-",
                l = d + "ixn-";
            a(u, function(t, e) {
                f[e] = o(d + e, !0, "api")
            }), f.addPageAction = o(d + "addPageAction", !0), f.setCurrentRouteName = o(d + "routeName", !0), e.exports = newrelic, f.interaction = function() {
                return (new r).get()
            };
            var p = r.prototype = {
                createTracer: function(t, e) {
                    var n = {},
                        r = this,
                        o = "function" == typeof e;
                    return i(l + "tracer", [Date.now(), t, n], r),
                        function() {
                            if (s.emit((o ? "" : "no-") + "fn-start", [Date.now(), r, o], n), o) try {
                                return e.apply(this, arguments)
                            } finally {
                                s.emit("fn-end", [Date.now()], n)
                            }
                        }
                }
            };
            a("setName,setAttribute,save,ignore,onEnd,getContext,end,get".split(","), function(t, e) {
                p[e] = o(l + e)
            }), newrelic.noticeError = function(t) {
                "string" == typeof t && (t = new Error(t)), i("err", [t, (new Date).getTime()])
            }
        }, {}],
        13: [function(t, e, n) {
            e.exports = function(t) {
                if ("string" == typeof t && t.length) return t.length;
                if ("object" == typeof t) {
                    if ("undefined" != typeof ArrayBuffer && t instanceof ArrayBuffer && t.byteLength) return t.byteLength;
                    if ("undefined" != typeof Blob && t instanceof Blob && t.size) return t.size;
                    if (!("undefined" != typeof FormData && t instanceof FormData)) try {
                        return JSON.stringify(t).length
                    } catch (e) {
                        return
                    }
                }
            }
        }, {}],
        14: [function(t, e, n) {
            var r = 0,
                o = navigator.userAgent.match(/Firefox[\/\s](\d+\.\d+)/);
            o && (r = +o[1]), e.exports = r
        }, {}],
        15: [function(t, e, n) {
            function r(t, e) {
                var n = [],
                    r = "",
                    i = 0;
                for (r in t) o.call(t, r) && (n[i] = e(r, t[r]), i += 1);
                return n
            }
            var o = Object.prototype.hasOwnProperty;
            e.exports = r
        }, {}],
        16: [function(t, e, n) {
            function r(t, e, n) {
                e || (e = 0), "undefined" == typeof n && (n = t ? t.length : 0);
                for (var r = -1, o = n - e || 0, i = Array(o < 0 ? 0 : o); ++r < o;) i[r] = t[e + r];
                return i
            }
            e.exports = r
        }, {}],
        17: [function(t, e, n) {
            function r(t) {
                return !(t && t instanceof Function && t.apply && !t[a])
            }
            var o = t("ee"),
                i = t(16),
                a = "nr@original",
                c = Object.prototype.hasOwnProperty,
                s = !1;
            e.exports = function(t, e) {
                function n(t, e, n, o) {
                    function nrWrapper() {
                        var r, a, c, s;
                        try {
                            a = this, r = i(arguments), c = "function" == typeof n ? n(r, a) : n || {}
                        } catch (f) {
                            l([f, "", [r, a, o], c])
                        }
                        u(e + "start", [r, a, o], c);
                        try {
                            return s = t.apply(a, r)
                        } catch (d) {
                            throw u(e + "err", [r, a, d], c), d
                        } finally {
                            u(e + "end", [r, a, s], c)
                        }
                    }
                    return r(t) ? t : (e || (e = ""), nrWrapper[a] = t, d(t, nrWrapper), nrWrapper)
                }

                function f(t, e, o, i) {
                    o || (o = "");
                    var a, c, s, f = "-" === o.charAt(0);
                    for (s = 0; s < e.length; s++) c = e[s], a = t[c], r(a) || (t[c] = n(a, f ? c + o : o, i, c))
                }

                function u(n, r, o) {
                    if (!s || e) {
                        var i = s;
                        s = !0;
                        try {
                            t.emit(n, r, o)
                        } catch (a) {
                            l([a, n, r, o])
                        }
                        s = i
                    }
                }

                function d(t, e) {
                    if (Object.defineProperty && Object.keys) try {
                        var n = Object.keys(t);
                        return n.forEach(function(n) {
                            Object.defineProperty(e, n, {
                                get: function() {
                                    return t[n]
                                },
                                set: function(e) {
                                    return t[n] = e, e
                                }
                            })
                        }), e
                    } catch (r) {
                        l([r])
                    }
                    for (var o in t) c.call(t, o) && (e[o] = t[o]);
                    return e
                }

                function l(e) {
                    try {
                        t.emit("internal-error", e)
                    } catch (n) {}
                }
                return t || (t = o), n.inPlace = f, n.flag = a, n
            }
        }, {}],
        ee: [function(t, e, n) {
            function r() {}

            function o(t) {
                function e(t) {
                    return t && t instanceof r ? t : t ? s(t, c, i) : i()
                }

                function n(n, r, o) {
                    if (!l.aborted) {
                        t && t(n, r, o);
                        for (var i = e(o), a = h(n), c = a.length, s = 0; s < c; s++) a[s].apply(i, r);
                        var f = u[y[n]];
                        return f && f.push([g, n, r, i]), i
                    }
                }

                function p(t, e) {
                    v[t] = h(t).concat(e)
                }

                function h(t) {
                    return v[t] || []
                }

                function m(t) {
                    return d[t] = d[t] || o(n)
                }

                function w(t, e) {
                    f(t, function(t, n) {
                        e = e || "feature", y[n] = e, e in u || (u[e] = [])
                    })
                }
                var v = {},
                    y = {},
                    g = {
                        on: p,
                        emit: n,
                        get: m,
                        listeners: h,
                        context: e,
                        buffer: w,
                        abort: a,
                        aborted: !1
                    };
                return g
            }

            function i() {
                return new r
            }

            function a() {
                (u.api || u.feature) && (l.aborted = !0, u = l.backlog = {})
            }
            var c = "nr@context",
                s = t("gos"),
                f = t(15),
                u = {},
                d = {},
                l = e.exports = o();
            l.backlog = u
        }, {}],
        gos: [function(t, e, n) {
            function r(t, e, n) {
                if (o.call(t, e)) return t[e];
                var r = n();
                if (Object.defineProperty && Object.keys) try {
                    return Object.defineProperty(t, e, {
                        value: r,
                        writable: !0,
                        enumerable: !1
                    }), r
                } catch (i) {}
                return t[e] = r, r
            }
            var o = Object.prototype.hasOwnProperty;
            e.exports = r
        }, {}],
        handle: [function(t, e, n) {
            function r(t, e, n, r) {
                o.buffer([t], r), o.emit(t, e, n)
            }
            var o = t("ee").get("handle");
            e.exports = r, r.ee = o
        }, {}],
        id: [function(t, e, n) {
            function r(t) {
                var e = typeof t;
                return !t || "object" !== e && "function" !== e ? -1 : t === window ? 0 : a(t, i, function() {
                    return o++
                })
            }
            var o = 1,
                i = "nr@id",
                a = t("gos");
            e.exports = r
        }, {}],
        loader: [function(t, e, n) {
            function r() {
                if (!b++) {
                    var t = g.info = NREUM.info,
                        e = d.getElementsByTagName("script")[0];
                    if (setTimeout(f.abort, 3e4), !(t && t.licenseKey && t.applicationID && e)) return f.abort();
                    s(v, function(e, n) {
                        t[e] || (t[e] = n)
                    }), c("mark", ["onload", a()], null, "api");
                    var n = d.createElement("script");
                    n.src = "https://" + t.agent, e.parentNode.insertBefore(n, e)
                }
            }

            function o() {
                "complete" === d.readyState && i()
            }

            function i() {
                c("mark", ["domContent", a()], null, "api")
            }

            function a() {
                return (new Date).getTime()
            }
            var c = t("handle"),
                s = t(15),
                f = t("ee"),
                u = window,
                d = u.document,
                l = "addEventListener",
                p = "attachEvent",
                h = u.XMLHttpRequest,
                m = h && h.prototype;
            NREUM.o = {
                ST: setTimeout,
                CT: clearTimeout,
                XHR: h,
                REQ: u.Request,
                EV: u.Event,
                PR: u.Promise,
                MO: u.MutationObserver
            }, t(12);
            var w = "" + location,
                v = {
                    beacon: "bam.nr-data.net",
                    errorBeacon: "bam.nr-data.net",
                    agent: "js-agent.newrelic.com/nr-1016.min.js"
                },
                y = h && m && m[l] && !/CriOS/.test(navigator.userAgent),
                g = e.exports = {
                    offset: a(),
                    origin: w,
                    features: {},
                    xhrWrappable: y
                };
            d[l] ? (d[l]("DOMContentLoaded", i, !1), u[l]("load", r, !1)) : (d[p]("onreadystatechange", o), u[p]("onload", r)), c("mark", ["firstbyte", a()], null, "api");
            var b = 0
        }, {}]
    }, {}, ["loader", 2, 10, 4, 3]);
    </script>
    <link rel="apple-touch-icon" href="/static/images/apple-touch-icon.8cc2fd27400e.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link href="//fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700,900,200italic,300italic,400italic,600italic,700italic,900italic" rel="stylesheet" type="text/css">
    <title>Exploration 63: Smart Pointers - Exploring C++ 11, Second Edition</title>
    <link rel="stylesheet" href="/static/CACHE/css/a1cf77ac2ed3.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="/static/css/annotator.min.fd58f69f4908.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <style type="text/css" title="ibis-book">
    #sbo-rt-content div {
        margin: 1em 1em 1em 1em
    }
    
    #sbo-rt-content a {
        text-decoration: none
    }
    
    #sbo-rt-content img {
        max-width: 100%;
        margin-top: 10pt
    }
    
    #sbo-rt-content p.booktitle {
        font-weight: bold;
        font-size: 2.5em;
        margin-top: 2em;
        margin-bottom: 0;
        text-align: center
    }
    
    #sbo-rt-content p.bookauthor {
        font-weight: bold;
        font-size: 1.7em;
        margin-top: .3em;
        margin-right: 2em;
        margin-bottom: 0;
        text-align: left
    }
    
    #sbo-rt-content p.booksubtitle {
        font-weight: bold;
        font-size: 1.7em;
        margin-top: 1em;
        margin-bottom: 7em;
        text-align: center;
        color: #8A8A8A
    }
    
    #sbo-rt-content .bookimage {
        font-size: 1.2em;
        margin-top: 0;
        margin-bottom: 1em;
        text-align: left
    }
    
    #sbo-rt-content .fmpara {
        font-size: .9em;
        text-indent: 0;
        margin-top: .5em;
        margin-bottom: .3em;
        text-align: justify
    }
    
    #sbo-rt-content .fmpara1 {
        font-size: .9em;
        text-indent: 0;
        margin-top: .4em;
        margin-bottom: .3em;
        text-align: right
    }
    
    #sbo-rt-content .inpara {
        text-indent: 0;
        margin-top: .4em;
        margin-left: 3em;
        margin-bottom: .3em
    }
    
    #sbo-rt-content .pub {
        margin-top: 10em;
        margin-bottom: 1em;
        text-align: right;
        margin-right: 5em
    }
    
    #sbo-rt-content .copyright {
        font-size: .9em;
        margin-top: .4em;
        margin-bottom: .4em;
        margin-left: 1.2em;
        margin-right: 1.2em;
        text-align: left
    }
    
    #sbo-rt-content .copyright1 {
        font-size: .9em;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 4em;
        margin-right: 3.3em;
        text-align: left;
        text-indent: -1.6em
    }
    
    #sbo-rt-content .copyright2 {
        font-size: .9em;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 4.2em
    }
    
    #sbo-rt-content .dedication {
        font-size: 1.1em;
        margin-bottom: 0;
        margin-top: 1.5em;
        text-align: center;
        margin-right: 0;
        font-style: italic
    }
    
    #sbo-rt-content .dedication1 {
        font-size: 1.1em;
        margin-bottom: 0;
        margin-top: .7em;
        text-align: center;
        margin-right: 0;
        font-style: normal
    }
    
    #sbo-rt-content .dedication2 {
        font-size: 1.2em;
        margin-bottom: 0;
        margin-top: .8em;
        text-align: center;
        margin-right: 1em
    }
    
    #sbo-rt-content .content-title {
        font-size: 1.6em;
        margin-top: 3em;
        margin-bottom: .1em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .fmtitle {
        font-size: 2.5em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-align: left;
        font-weight: bold;
        border-bottom: 1.1px solid black;
        padding-bottom: .8em
    }
    
    #sbo-rt-content .right {
        text-indent: 0;
        margin-top: 1em;
        margin-right: 1.5em;
        margin-bottom: .3em;
        text-align: right
    }
    
    #sbo-rt-content .right1 {
        text-indent: 0;
        margin-top: 0;
        margin-right: 1.5em;
        margin-bottom: .2em;
        text-align: right
    }
    
    #sbo-rt-content .chapimage {
        margin-left: .2em;
        margin-top: 1.5em;
        margin-bottom: 1.5em;
        text-align: left
    }
    
    #sbo-rt-content p.ChapterNumber {
        font-weight: bold;
        font-size: 1.7em;
        margin-top: 10px;
        margin-left: 0;
        margin-bottom: 5px;
        text-align: left
    }
    
    #sbo-rt-content p.ChapterTitle {
        font-weight: bold;
        font-size: 2.5em;
        margin-top: 0;
        margin-bottom: 1em;
        margin-left: 0;
        text-align: left;
        border-bottom: 1.1px solid black;
        padding-bottom: .8em
    }
    
    #sbo-rt-content p.PartNumber {
        font-weight: bold;
        font-size: 1.7em;
        margin-top: 10px;
        margin-left: 0;
        margin-bottom: 5px;
        text-align: left;
        padding-bottom: .8em
    }
    
    #sbo-rt-content p.partTitle {
        font-weight: bold;
        font-size: 2.5em;
        margin-top: 1em;
        margin-bottom: 1em;
        margin-left: 0;
        text-align: left
    }
    
    #sbo-rt-content .paraaftertitle {
        font-size: 100%;
        text-indent: 0;
        margin-top: 0;
        margin-left: 0;
        margin-bottom: 0
    }
    
    #sbo-rt-content p.noindent {
        font-size: 100%;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.noindent1 {
        font-size: 100%;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: 1em
    }
    
    #sbo-rt-content p.noindent2 {
        font-size: 100%;
        text-indent: 0;
        margin-top: 1.5em;
        margin-bottom: 1em
    }
    
    #sbo-rt-content p.noindent3 {
        font-size: 100%;
        text-indent: 0;
        margin-top: .2em;
        margin-bottom: 1.5em;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.noindent4 {
        font-size: 100%;
        text-indent: 0;
        margin-top: .7em;
        margin-bottom: .2em;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content span.listing {
        font-weight: bold
    }
    
    #sbo-rt-content p.indent {
        font-size: 100%;
        text-indent: 1.5em;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.indentt {
        font-size: 100%;
        text-indent: 1.2em;
        margin-top: 1em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.indent1 {
        font-size: 100%;
        text-indent: 1.2em;
        margin-top: 0;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.indent1a {
        font-size: 100%;
        text-indent: 1.5em;
        margin-top: 0;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 4.5em;
        text-align: right
    }
    
    #sbo-rt-content p.indent2 {
        font-size: 100%;
        margin-top: .8em;
        margin-bottom: .8em;
        margin-left: 2.4em;
        margin-right: 2.4em;
        text-align: justify;
        font-style: italic
    }
    
    #sbo-rt-content p.indent3 {
        font-size: 100%;
        text-indent: 1em;
        margin-top: .8em;
        margin-bottom: .8em;
        margin-left: 1.8em;
        margin-right: 1.8em;
        text-align: left
    }
    
    #sbo-rt-content p.indent4 {
        font-size: 100%;
        text-indent: 1.3em;
        margin-top: .5em;
        margin-bottom: .5em;
        margin-left: 2em;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content .blockquote {
        font-size: 100%;
        text-indent: .2em;
        margin-top: 1em;
        margin-left: 2em;
        margin-right: 1em;
        margin-bottom: 1em;
        text-align: justify
    }
    
    #sbo-rt-content .block-noin {
        font-size: 100%;
        text-indent: 0;
        margin-top: .5em;
        margin-left: 0;
        margin-right: 1em;
        margin-bottom: 0;
        text-align: justify
    }
    
    #sbo-rt-content p.noindent-block {
        font-size: 100%;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 1.5em;
        text-align: justify
    }
    
    #sbo-rt-content .blockquote1 {
        font-size: 100%;
        text-indent: .2em;
        margin-top: .7em;
        margin-left: 4em;
        margin-right: 2em;
        margin-bottom: 1em;
        text-align: left
    }
    
    #sbo-rt-content .block-noin1 {
        font-size: 100%;
        text-indent: .2em;
        margin-top: 2em;
        margin-left: 0;
        margin-right: 1em;
        margin-bottom: 2em;
        text-align: justify
    }
    
    #sbo-rt-content p.Heading1 {
        font-weight: bold;
        font-size: 2em;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: .2em
    }
    
    #sbo-rt-content p.Heading2 {
        font-size: 1.6em;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: .3em
    }
    
    #sbo-rt-content p.Heading2-a {
        font-size: 1.6em;
        text-indent: 0;
        margin-top: .2em;
        margin-bottom: .3em
    }
    
    #sbo-rt-content p.Heading2a {
        font-size: 1.5em;
        text-indent: 0;
        margin-top: .7em;
        margin-bottom: .3em;
        font-weight: bold
    }
    
    #sbo-rt-content p.Heading3 {
        font-weight: bold;
        font-size: 1.45em;
        text-indent: 0;
        margin-top: 1.2em;
        margin-bottom: .1em
    }
    
    #sbo-rt-content p.Heading3a {
        font-weight: normal;
        font-size: 1.25em;
        text-indent: 0;
        margin-top: 1.2em;
        margin-bottom: .1em
    }
    
    #sbo-rt-content p.Heading4 {
        font-size: 1.3em;
        text-indent: 0;
        margin-top: 1.3em;
        margin-bottom: .3em;
        text-align: left
    }
    
    #sbo-rt-content .img1 {
        text-align: left
    }
    
    #sbo-rt-content .img1a {
        text-align: right;
        margin-right: 5em;
        margin-top: 5em
    }
    
    #sbo-rt-content .img2 {
        text-align: left;
        margin-bottom: 1.5em
    }
    
    #sbo-rt-content div.Figure {
        font-size: small;
        margin-top: 1.5em;
        margin-bottom: 1.5em
    }
    
    #sbo-rt-content .para-1 {
        font-size: 100%;
        margin-top: 1em;
        text-indent: 1.5em;
        margin-bottom: 0;
        text-align: left
    }
    
    #sbo-rt-content .para-2 {
        font-size: .9em;
        text-indent: -1.4em;
        margin-left: 2.4em;
        margin-top: .5em;
        margin-bottom: 0
    }
    
    #sbo-rt-content .figurecaption {
        font-size: small;
        margin-top: 0;
        margin-bottom: 0;
        text-align: justify
    }
    
    #sbo-rt-content .image {
        text-align: center
    }
    
    #sbo-rt-content .codecaption {
        font-size: 100%;
        margin-top: .6em;
        margin-bottom: .6em;
        text-align: justify;
        font-style: italic
    }
    
    #sbo-rt-content .PCode {
        font-size: small;
        margin-top: 1em;
        margin-bottom: 1em;
        margin-left: 0;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content .PCode-1 {
        font-size: small;
        margin-top: 1em;
        margin-bottom: .1em;
        margin-left: 0;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content .PCode-2 {
        font-size: small;
        margin-top: 0;
        margin-bottom: 0;
        margin-left: 0;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content .PCode-3 {
        font-size: small;
        margin-top: 0;
        margin-bottom: 1em;
        margin-left: 0;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content div.singlethin {
        border-bottom: solid 3px;
        margin-left: 1em;
        margin-right: 1em;
        margin-bottom: 1em
    }
    
    #sbo-rt-content p.box-left {
        font-size: 100%;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: 0;
        margin-left: 1em;
        margin-right: 1em;
        text-align: left
    }
    
    #sbo-rt-content div.singlethin1 {
        margin-left: 2em;
        margin-right: 2em
    }
    
    #sbo-rt-content .inlinecode {
        font-family: monospace
    }
    
    #sbo-rt-content div.notepara {
        font-size: 110%;
        text-indent: 0;
        margin-top: 1em;
        border-top: solid 1px;
        border-bottom: solid 1px;
        margin-bottom: 1em;
        text-align: justify
    }
    
    #sbo-rt-content span.pink-box {
        font-weight: bold;
        padding-left: 1.3em;
        padding-right: 1.3em;
        border: 1.1px solid black;
        font-size: 1.5em;
        margin-top: .5em;
        margin-bottom: .5em;
        text-indent: 0;
        text-align: justify
    }
    
    #sbo-rt-content span.courier {
        font-family: Courier New;
        font-weight: normal;
        font-style: normal;
        font-size: 100%
    }
    
    #sbo-rt-content div.courier {
        font-family: Courier New;
        font-weight: normal;
        font-style: normal;
        font-size: 100%;
        margin-top: 1em;
        margin-bottom: 1em
    }
    
    #sbo-rt-content div.boxcourier {
        font-family: Courier New;
        font-weight: normal;
        font-style: normal;
        font-size: 100%;
        margin-top: 1em;
        margin-bottom: 1em;
        margin-left: 1.5em;
        margin-right: 1.5em;
        text-align: left
    }
    
    #sbo-rt-content span.courier1 {
        font-family: Courier New;
        font-weight: normal;
        font-style: normal;
        font-size: 95%
    }
    
    #sbo-rt-content .boxhead {
        font-size: 1.25em;
        font-weight: bold;
        padding-left: .1em;
        padding-bottom: .1em;
        padding-top: .1em;
        margin-top: 0;
        text-indent: 0;
        text-align: center;
        border: 3px solid black
    }
    
    #sbo-rt-content div.box {
        margin-top: 1em;
        margin-bottom: 1em
    }
    
    #sbo-rt-content .boxpara {
        font-size: 110%;
        text-indent: 0;
        margin-left: 1.5em;
        margin-right: 1.5em;
        margin-top: .5em;
        margin-bottom: .5em;
        text-align: left
    }
    
    #sbo-rt-content .alpha {
        font-size: 1.2em;
        font-weight: bold;
        margin-left: .2em;
        margin-top: 1em;
        margin-bottom: .3em;
        text-align: left
    }
    
    #sbo-rt-content .index {
        font-size: 1em;
        margin-left: .2em;
        margin-top: 0;
        margin-bottom: 0;
        text-align: left
    }
    
    #sbo-rt-content .index1 {
        font-size: 1em;
        margin-left: 1.7em;
        margin-top: 0;
        margin-bottom: 0;
        text-align: left
    }
    
    #sbo-rt-content .index2 {
        font-size: 1em;
        margin-left: 3.3em;
        margin-top: 0;
        margin-bottom: 0;
        text-align: left
    }
    
    #sbo-rt-content .cover {
        text-align: center
    }
    
    #sbo-rt-content .top {
        border-top: 1.1px solid black;
        border-bottom: 2px solid black
    }
    
    #sbo-rt-content .bot {
        border-bottom: 2px solid black
    }
    
    #sbo-rt-content table.bodytable,
    #sbo-rt-content table {
        border-collapse: collapse;
        margin-bottom: 8px;
        font-size: small;
        margin-top: 10pt;
        width: 95%;
        border-top: 0 solid black;
        border-bottom: 0 solid black
    }
    
    #sbo-rt-content table.fmtable {
        margin-bottom: 1em;
        font-size: 1em;
        margin-left: 4em;
        border-top: 0 solid #FFF;
        border-bottom: 0 solid #FFF
    }
    
    #sbo-rt-content table {
        margin-bottom: 1em;
        border-top: 1.1px solid black;
        border-bottom: 1.1px solid black;
        border-collapse: collapse
    }
    
    #sbo-rt-content th {
        border-top: 1px solid black;
        border-bottom: 1px solid black;
        padding-right: 1.5em
    }
    
    #sbo-rt-content td {
        font-size: small;
        padding-right: 1.5em;
        margin-top: 0;
        margin-bottom: 1em
    }
    
    #sbo-rt-content .tablepara {
        font-size: small;
        text-indent: 0;
        margin-top: 0;
        margin-bottom: .5em;
        padding-right: 1.5em
    }
    
    #sbo-rt-content .tablepara1 {
        font-size: small;
        margin-left: 2em;
        margin-top: 0;
        margin-bottom: 0;
        padding-right: 1.5em
    }
    
    #sbo-rt-content .header {
        border-bottom: 1.1px solid black;
        text-indent: 0;
        text-align: left
    }
    
    #sbo-rt-content .header1 {
        border-top: 1.1px solid black;
        text-indent: 0;
        text-align: left
    }
    
    #sbo-rt-content .TabCapt {
        font-style: italic;
        margin-left: 0;
        text-indent: 0;
        margin-top: .2em;
        margin-bottom: 0
    }
    
    #sbo-rt-content .FigCapt {
        font-style: italic;
        font-size: .9em
    }
    
    #sbo-rt-content .CaptNr {
        font-weight: bold
    }
    
    #sbo-rt-content .ttitle {
        font-style: Italic;
        margin-bottom: 1em
    }
    
    #sbo-rt-content p.paraaftertitle1 {
        font-size: .9em;
        text-indent: 0;
        margin-top: .5em;
        margin-bottom: .8em;
        text-align: left
    }
    
    #sbo-rt-content p.para {
        font-size: small;
        text-indent: 20px;
        margin-top: 0;
        margin-bottom: 0;
        text-align: justify
    }
    
    #sbo-rt-content p.quote {
        font-style: italic;
        font-size: 100%;
        margin-top: 1.5em;
        margin-left: 2.5em;
        margin-right: 2.5em;
        margin-bottom: 0
    }
    
    #sbo-rt-content p.quotesource {
        font-size: small;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: 1em;
        text-align: right
    }
    
    #sbo-rt-content p.chaptersubtitle {
        font-size: x-large;
        text-indent: 0;
        margin-top: 0;
        margin-left: 0;
        margin-bottom: 0;
        text-align: left
    }
    
    #sbo-rt-content p.line {
        margin-top: .3em;
        border-bottom: 1px solid black
    }
    
    #sbo-rt-content p.line1 {
        margin-top: .3em;
        margin-bottom: 1.5em;
        border-bottom: 1px solid black
    }
    
    #sbo-rt-content p.line2 {
        margin-top: 5em;
        margin-bottom: 5em;
        border-bottom: 1px solid black;
        text-align: center;
        margin-left: 15em;
        margin-right: 15em
    }
    
    #sbo-rt-content li {
        margin-bottom: .5em;
        margin-top: .5em
    }
    
    #sbo-rt-content p.alpha {
        font-size: 1.2em;
        font-weight: bold;
        margin-left: .2em;
        margin-top: 1em;
        margin-bottom: .3em;
        text-align: left
    }
    
    #sbo-rt-content ul.bulleted-list {
        font-size: 100%;
        text-align: left;
        margin-left: 5em;
        margin-right: 3em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0
    }
    
    #sbo-rt-content ul.bulletedin-list {
        font-size: 100%;
        text-align: left;
        margin-left: 6em;
        margin-right: 3em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0
    }
    
    #sbo-rt-content ul.bulleted {
        font-size: 100%;
        text-align: left;
        margin-left: 3em;
        margin-right: 3em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0
    }
    
    #sbo-rt-content ul.bulleted-thin {
        font-size: 100%;
        text-align: left;
        margin-left: 1em;
        margin-right: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0
    }
    
    #sbo-rt-content ol.OrderedList {
        font-size: 100%;
        text-align: left;
        margin-left: 4em;
        margin-right: 3em;
        margin-top: 1em;
        margin-bottom: 1em
    }
    
    #sbo-rt-content ul.bulleted1 {
        font-size: 100%;
        text-align: left;
        margin-left: 0;
        margin-right: 5em;
        margin-top: 1em;
        margin-bottom: 1em;
        list-style-type: none
    }
    
    #sbo-rt-content ul.bulleted1_a {
        font-size: 100%;
        text-align: justify;
        margin-left: 0;
        margin-right: 5em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0;
        list-style-type: none
    }
    
    #sbo-rt-content ul.bulleted2 {
        font-size: 100%;
        text-align: justify;
        margin-left: 2.3em;
        margin-right: 5em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0
    }
    
    #sbo-rt-content ul.bulleted4 {
        font-size: 100%;
        text-align: center;
        margin-left: 1.3em;
        margin-right: 5em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0;
        list-style-type: none
    }
    
    #sbo-rt-content .numbered {
        font-size: small;
        text-align: justify;
        margin-left: 2em;
        margin-right: 2em;
        margin-top: .5em;
        margin-bottom: .5em;
        text-indent: 1em
    }
    
    #sbo-rt-content .bulletedin {
        font-size: 100%;
        text-align: justify;
        margin-left: 3.8em;
        margin-right: 4em;
        margin-top: .5em;
        margin-bottom: .5em
    }
    
    #sbo-rt-content .bulletedin1 {
        font-size: 100%;
        text-align: justify;
        margin-left: 4.5em;
        margin-right: 4em;
        margin-top: .5em;
        margin-bottom: .5em
    }
    
    #sbo-rt-content ul.None {
        font-size: .9em;
        text-align: justify;
        margin-left: 3em;
        margin-right: 2em;
        margin-top: .5em;
        margin-bottom: .5em;
        list-style-type: none
    }
    
    #sbo-rt-content .Listing {
        font-size: small;
        margin-bottom: 0
    }
    
    #sbo-rt-content .PCode1 {
        font-size: small;
        margin-top: .7em;
        margin-bottom: 0;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content .PCode2 {
        font-size: small;
        margin-top: 1em;
        margin-bottom: .1em;
        margin-left: 2.2em;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content .PCode3 {
        font-size: small;
        margin-top: 0;
        margin-left: 2.2em;
        margin-bottom: .1em;
        text-align: left;
        font-family: monospace
    }
    
    #sbo-rt-content .NoteCaption {
        font-size: small;
        margin-top: 1.3em;
        margin-left: 5em;
        margin-right: 5em;
        border: 1.1px solid black;
        padding: .5em;
        margin-bottom: 1.3em
    }
    
    #sbo-rt-content .Table {
        font-size: 100%;
        margin-bottom: 1em;
        margin-top: 1em;
        margin-left: 0
    }
    
    #sbo-rt-content .toc {
        font-size: 1.1em;
        margin-top: .2em;
        margin-bottom: .1em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .toc-p {
        font-size: 1.5em;
        margin-top: .5em;
        margin-bottom: .1em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .toca {
        font-size: 1.1em;
        margin-top: 1em;
        margin-bottom: .4em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .toc1 {
        font-size: 1.2em;
        margin-top: .4em;
        margin-bottom: .3em;
        text-align: left;
        margin-left: 0;
        text-indent: 0;
        font-weight: bold
    }
    
    #sbo-rt-content .toc2 {
        font-size: 1.1em;
        margin-top: .4em;
        margin-bottom: .3em;
        text-align: left;
        margin-left: 1.2em;
        text-indent: 0;
        font-weight: normal
    }
    
    #sbo-rt-content .toc3 {
        font-size: .9em;
        margin-top: .4em;
        margin-bottom: .3em;
        text-align: left;
        margin-left: 3.8em;
        text-indent: 0;
        font-weight: normal
    }
    
    #sbo-rt-content .toc4 {
        font-size: 1.1em;
        margin-top: .2em;
        margin-bottom: .5em;
        margin-left: 0;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .tocch {
        font-size: 1.3em;
        margin-top: .7em;
        margin-bottom: .7em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .noborder {
        margin-bottom: 1em;
        border-top: 0 solid #FFF;
        border-bottom: 0 solid #FFF
    }
    
    #sbo-rt-content .authurright {
        text-align: right;
        margin-top: 0;
        margin-bottom: 0
    }
    
    #sbo-rt-content .FormalPara {
        font-size: small;
        margin-bottom: .7em
    }
    
    #sbo-rt-content .FontName1 {
        font-size: 100%;
        font-family: "Courier New", Courier, monospace
    }
    
    #sbo-rt-content span.FontName2 {
        font-size: 100%;
        font-family: "Courier New", Courier, monospace
    }
    
    #sbo-rt-content span.FontName3 {
        font-size: 100%;
        font-family: "Courier New", Courier, monospace
    }
    
    #sbo-rt-content .rightarrow {
        margin-top: 0
    }
    
    #sbo-rt-content div.thinline {
        margin-top: 1em;
        margin-bottom: 1em;
        border-top: solid 4px #AFAFB0;
        border-bottom: solid 4px #AFAFB0
    }
    
    #sbo-rt-content span.line {
        text-decoration: underline
    }
    
    #sbo-rt-content span.underline {
        text-decoration: underline
    }
    
    #sbo-rt-content div.box {
        border-top: solid 2px;
        border-bottom: solid 2px
    }
    
    #sbo-rt-content .app {
        font-size: 150%;
        margin-left: .8em
    }
    
    #sbo-rt-content .page {
        text-decoration: none;
        color: #000
    }
    
    #sbo-rt-content .cXXX {
        text-decoration: none;
        color: #000
    }
    
    #sbo-rt-content .textindent {
        margin-left: 1.7em;
        margin-top: 1em;
        margin-bottom: 1em;
        font-size: 100%
    }
    
    #sbo-rt-content .textindent1 {
        margin-left: 1.7em;
        margin-top: 0;
        margin-bottom: 0;
        font-size: 100%
    }
    
    #sbo-rt-content .textindent2 {
        margin-left: 1.7em;
        margin-top: 0;
        margin-bottom: 0;
        font-size: 100%;
        text-indent: 1em
    }
    
    #sbo-rt-content p.FootNote {
        margin-top: .8em;
        margin-bottom: 0;
        font-size: 85%;
        text-indent: 0;
        text-align: left;
        margin-left: 0;
        margin-right: 0
    }
    
    #sbo-rt-content pre {
        margin-left: 0;
        font-family: monospace;
        white-space: pre-wrap
    }
    
    #sbo-rt-content p.Heading4a {
        font-size: 1.15em;
        font-weight: bold;
        text-indent: 1em;
        margin-top: 1.3em;
        margin-bottom: .3em;
        border-top: 3px solid #4d4d4c;
        border-left: solid 3px #4d4d4c;
        border-right: solid 3px #4d4d4c;
        border-bottom: solid 3px #4d4d4c;
        text-align: center
    }
    
    #sbo-rt-content p.noindent8 {
        font-size: 100%;
        text-indent: 0;
        margin-top: 1em;
        margin-bottom: 1em;
        text-align: center;
        font-weight: bold;
        color: #8A8A8A
    }
    
    #sbo-rt-content .tocb {
        font-size: 1.4em;
        margin-top: .5em;
        margin-bottom: .2em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content .part {
        font-weight: normal;
        font-size: 1em;
        margin-bottom: 5px;
        text-align: left;
        padding-left: 1.3em;
        padding-bottom: 10em;
        padding-right: 1.3em;
        border: 1.1px solid black
    }
    
    #sbo-rt-content p.Heading5 {
        font-size: 1em;
        text-indent: 0;
        margin-top: 1.3em;
        margin-bottom: .3em;
        text-align: left;
        font-weight: bold
    }
    
    #sbo-rt-content p.noindent5s {
        font-size: 100%;
        text-indent: 0;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: right
    }
    
    #sbo-rt-content span.strike {
        text-decoration: line-through
    }
    
    #sbo-rt-content p.tab-left {
        font-size: 100%;
        text-indent: 0;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.tab-leftt {
        font-size: 100%;
        text-indent: 0;
        margin-top: .5em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.tab-rightt {
        font-size: 100%;
        text-indent: 0;
        margin-top: .5em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: right
    }
    
    #sbo-rt-content p.tab-center {
        font-size: 100%;
        text-indent: 0;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: center
    }
    
    #sbo-rt-content p.tab-centert {
        font-size: 100%;
        text-indent: 0;
        margin-top: .5em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: center
    }
    
    #sbo-rt-content p.tab-right {
        font-size: 100%;
        text-indent: 0;
        margin-top: .1em;
        margin-bottom: .1em;
        margin-left: 0;
        margin-right: 0;
        text-align: right
    }
    
    #sbo-rt-content .center {
        text-indent: 0;
        margin-top: .5em;
        margin-right: 0;
        margin-bottom: .3em;
        text-align: center
    }
    
    #sbo-rt-content .img-vert {
        vertical-align: middle
    }
    
    #sbo-rt-content ol.list1 {
        list-style-type: lower-alpha;
        margin-left: 0;
        text-align: left
    }
    
    #sbo-rt-content ol.listnone {
        list-style-type: none;
        margin-left: 0;
        text-align: left
    }
    
    #sbo-rt-content .bull {
        font-size: 100%;
        text-align: left;
        margin-left: 0;
        margin-right: 3em;
        margin-top: 1em;
        margin-bottom: 1em;
        text-indent: 0
    }
    
    #sbo-rt-content .list1 {
        font-size: 100%;
        margin-bottom: 0;
        margin-left: 3.5em;
        text-align: left
    }
    
    #sbo-rt-content .listin {
        font-size: 90%;
        margin-top: .5em;
        margin-bottom: 0;
        margin-left: 6em;
        text-align: left
    }
    
    #sbo-rt-content .list1in {
        font-size: 90%;
        margin-top: .5em;
        margin-bottom: 0;
        margin-left: 6.3em;
        text-align: left
    }
    
    #sbo-rt-content p.tab-foot {
        font-size: 100%;
        text-indent: 0;
        margin-top: .1em;
        margin-bottom: 0;
        margin-left: 0;
        margin-right: 0;
        text-align: left
    }
    
    #sbo-rt-content p.ChapterTitlei {
        font-weight: bold;
        font-size: 2.8em;
        margin-top: 0;
        margin-bottom: 1em;
        margin-left: 0;
        text-align: left;
        border-bottom: 1.1px solid black;
        padding-bottom: .8em
    }
    
    #sbo-rt-content p.Heading2ai {
        font-size: 1.5em;
        text-indent: 0;
        margin-top: .7em;
        margin-bottom: .3em;
        font-weight: bold
    }
    </style>
    <script>
    // <![CDATA[
    var g = {
        position_cache: {

            "chapter": "/api/v1/book/9781430261933/chapter/9781430261933_Ch63.xhtml",
            "book_id": "9781430261933",
            "chapter_uri": "9781430261933_Ch63.xhtml",
            "position": 0,
            "user_uuid": "1107e915-1a0f-475d-bf54-b400da13cc4d",
            "next_chapter_uri": "/library/view/exploring-c-11/9781430261933/9781430261933_Ch64.xhtml"

        },
        title: "Exploring C++ 11, Second Edition",
        author_list: "Ray Lischner",
        format: "book",
        source: "application/epub+zip",
        is_system_book: true,
        is_public: false,
        loaded_from_server: true,
        allow_scripts: false,
        has_mathml: false,
        show_ios_app_teaser: false
    };
    // ]]>
    </script>
    <script src="/static/js/src/modernizr.js"></script>
    <script>
    window.PUBLIC_ANNOTATIONS = true;






    window.MOBILE_PUBLIC_ANNOTATIONS = false;





    window.PRIVACY_CONTROL_OVERRIDE = false;



    window.PRIVACY_CONTROL_SWITCH = true;



    window.PUBLISHER_PAGES = true;


    window.SBO = {
        "constants": {
            "SITB_ENDPOINT": "https://www.safaribooksonline.com/api/v2/sitb/",
            "ENABLE_ONLINE_TRAINING": true
        }
    };
    </script>
    <link rel="canonical" href="https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml">
    <meta name="description" content="EXPLORATION 63 Smart Pointers The std::unique_ptr class template is an example of a so-called smart pointer. A smart pointer behaves much like any other pointer but with extra features ... ">
    <meta property="og:title" content="Exploration 63: Smart Pointers">
    <meta itemprop="isPartOf" content="/library/view/exploring-c-11/9781430261933/">
    <meta itemprop="name" content="Exploration 63: Smart Pointers">
    <meta property="og:url" itemprop="url" content="https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml">
    <meta property="og:site_name" content="Safari">
    <meta property="og:image" itemprop="thumbnailUrl" content="https://www.safaribooksonline.com/library/cover/9781430261933/">
    <meta property="og:description" itemprop="description" content="EXPLORATION 63 Smart Pointers The std::unique_ptr class template is an example of a so-called smart pointer. A smart pointer behaves much like any other pointer but with extra features ... ">
    <meta itemprop="inLanguage" content="en">
    <meta itemprop="publisher" content="Apress">
    <meta property="og:type" content="book">
    <meta property="og:book:isbn" itemprop="isbn" content="9781430261933">
    <meta property="og:book:author" itemprop="author" content="Ray Lischner">
    <meta property="og:book:tag" itemprop="about" content="C++">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:site" content="@safari">
    <style type="text/css" id="font-styles" data-template="#sbo-rt-content, #sbo-rt-content p, #sbo-rt-content div { font-size: <%= font_size %> !important; }"></style>
    <style type="text/css" id="font-family" data-template="#sbo-rt-content, #sbo-rt-content p, #sbo-rt-content div { font-family: <%= font_family %> !important; }"></style>
    <style type="text/css" id="column-width" data-template="#sbo-rt-content { max-width: <%= column_width %>% !important; margin: 0 auto !important; }"></style>
    <!--[if lt IE 9]><script src="/static/js/src/respond.min.cf5c9b7980e5.js"></script><![endif]-->
    <noscript>&lt;meta http-equiv="refresh" content="0; url=/library/no-js/" /&gt;</noscript>
    <script type="text/javascript">
    (function(i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r;
        i[r] = i[r] || function() {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date();
        a = s.createElement(o), m = s.getElementsByTagName(o)[0];
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

    var matches = document.cookie.match(/BrowserCookie\s*=\s*([a-f0-9\-]{36})/),
        user_uuid = null;

    if (matches && matches.length === 2) {
        user_uuid = matches[1];
    }


    ga('create', 'UA-39299553-7', {
        'userId': '1107e915-1a0f-475d-bf54-b400da13cc4d'
    });


    ga('set', 'dimension1', 'B2B');
    ga('set', 'dimension6', user_uuid);


    ga('set', 'dimension2', '1107e915-1a0f-475d-bf54-b400da13cc4d');

    ga('set', 'dimension7', '00100000005hJyjAAE');





    //enable enhanced link tracking
    ga('require', 'linkid', 'linkid.js');

    // reading interface will track pageviews itself
    if (document.location.pathname.indexOf("/library/view") !== 0) {
        ga('send', 'pageview');
    }
    </script>
    <script src="/static/js/build/vendor.51107079d13b.js"></script>
    <script src="/static/js/build/reader.9a0588ef26bb.js"></script>
    <script async="" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML.js&amp;delayStartupUntil=configured"></script>
    <style id="annotator-dynamic-style">
    .annotator-adder,
    .annotator-outer,
    .annotator-notice {
        z-index: 100019;
    }
    
    .annotator-filter {
        z-index: 100009;
    }
    </style>
</head>

<body class="reading sidenav  scalefonts library nav-collapsed">
    <div class="hide working" role="status">
        <div class="working-image"></div>
    </div>
    <div class="sbo-site-nav">
        <a href="#container" class="skip">Skip to content</a>
        <header class="topbar t-topbar">
            <nav role="navigation" class="js-site-nav">
                <ul class="topnav">
                    <li class="t-logo">
                        <a href="/home/" class="l0 None safari-home nav-icn js-keyboard-nav-home">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="20" height="20" version="1.1" fill="#4A3C31">
                                <desc>Safari Home Icon</desc>
                                <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                    <path d="M4 9.9L4 9.9 4 18 16 18 16 9.9 10 4 4 9.9ZM2.6 8.1L2.6 8.1 8.7 1.9 10 0.5 11.3 1.9 17.4 8.1 18 8.7 18 9.5 18 18.1 18 20 16.1 20 3.9 20 2 20 2 18.1 2 9.5 2 8.7 2.6 8.1Z"></path>
                                    <rect x="10" y="12" width="3" height="7"></rect>
                                    <rect transform="translate(18.121320, 10.121320) rotate(-315.000000) translate(-18.121320, -10.121320) " x="16.1" y="9.1" width="4" height="2"></rect>
                                    <rect transform="translate(2.121320, 10.121320) scale(-1, 1) rotate(-315.000000) translate(-2.121320, -10.121320) " x="0.1" y="9.1" width="4" height="2"></rect>
                                </g>
                            </svg><span>Safari Home</span></a>
                    </li>
                    <li>
                        <a href="/r/" class="t-recommendations-nav l0 nav-icn None">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="20" height="20" version="1.1" fill="#4A3C31">
                                <desc>recommendations icon</desc>
                                <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                    <path d="M50 25C50 18.2 44.9 12.5 38.3 11.7 37.5 5.1 31.8 0 25 0 18.2 0 12.5 5.1 11.7 11.7 5.1 12.5 0 18.2 0 25 0 31.8 5.1 37.5 11.7 38.3 12.5 44.9 18.2 50 25 50 31.8 50 37.5 44.9 38.3 38.3 44.9 37.5 50 31.8 50 25ZM25 3.1C29.7 3.1 33.6 6.9 34.4 11.8 30.4 12.4 26.9 15.1 25 18.8 23.1 15.1 19.6 12.4 15.6 11.8 16.4 6.9 20.3 3.1 25 3.1ZM34.4 15.6C33.6 19.3 30.7 22.2 27.1 22.9 27.8 19.2 30.7 16.3 34.4 15.6ZM22.9 22.9C19.2 22.2 16.3 19.3 15.6 15.6 19.3 16.3 22.2 19.2 22.9 22.9ZM3.1 25C3.1 20.3 6.9 16.4 11.8 15.6 12.4 19.6 15.1 23.1 18.8 25 15.1 26.9 12.4 30.4 11.8 34.4 6.9 33.6 3.1 29.7 3.1 25ZM22.9 27.1C22.2 30.7 19.3 33.6 15.6 34.4 16.3 30.7 19.2 27.8 22.9 27.1ZM25 46.9C20.3 46.9 16.4 43.1 15.6 38.2 19.6 37.6 23.1 34.9 25 31.3 26.9 34.9 30.4 37.6 34.4 38.2 33.6 43.1 29.7 46.9 25 46.9ZM27.1 27.1C30.7 27.8 33.6 30.7 34.4 34.4 30.7 33.6 27.8 30.7 27.1 27.1ZM38.2 34.4C37.6 30.4 34.9 26.9 31.3 25 34.9 23.1 37.6 19.6 38.2 15.6 43.1 16.4 46.9 20.3 46.9 25 46.9 29.7 43.1 33.6 38.2 34.4Z"></path>
                                </g>
                            </svg><span>Recommended</span></a>
                    </li>
                    <li>
                        <a href="/s/" class="t-queue-nav l0 nav-icn None">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="20" height="20" version="1.1" fill="#4A3C31">
                                <desc>queue icon</desc>
                                <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                    <path d="M25 29.2C25.4 29.2 25.8 29.1 26.1 28.9L48.7 16.8C49.5 16.4 50 15.5 50 14.6 50 13.7 49.5 12.8 48.7 12.4L26.1 0.3C25.4-0.1 24.6-0.1 23.9 0.3L1.3 12.4C0.5 12.8 0 13.7 0 14.6 0 15.5 0.5 16.4 1.3 16.8L23.9 28.9C24.2 29.1 24.6 29.2 25 29.2ZM7.3 14.6L25 5.2 42.7 14.6 25 24 7.3 14.6ZM48.7 22.4L47.7 21.9 25 34.2 2.3 21.9 1.3 22.4C0.5 22.9 0 23.7 0 24.7 0 25.6 0.5 26.5 1.3 26.9L23.9 39.3C24.2 39.5 24.6 39.6 25 39.6 25.4 39.6 25.8 39.5 26.1 39.3L48.7 26.9C49.5 26.5 50 25.6 50 24.7 50 23.7 49.5 22.9 48.7 22.4ZM48.7 32.8L47.7 32.3 25 44.6 2.3 32.3 1.3 32.8C0.5 33.3 0 34.1 0 35.1 0 36 0.5 36.9 1.3 37.3L23.9 49.7C24.2 49.9 24.6 50 25 50 25.4 50 25.8 49.9 26.1 49.7L48.7 37.3C49.5 36.9 50 36 50 35.1 50 34.1 49.5 33.3 48.7 32.8Z"></path>
                                </g>
                            </svg><span>
              
                Queue
              
            </span></a>
                    </li>
                    <li class="search">
                        <a href="#" class="t-search-nav trigger nav-icn l0" data-dropdown-selector=".searchbox">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="20" height="20" version="1.1" fill="#4A3C31">
                                <desc>search icon</desc>
                                <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                    <path d="M31.3 0C20.9 0 12.5 8.4 12.5 18.8 12.5 22.5 13.6 25.9 15.4 28.8L1.2 42.9C-0.4 44.5-0.4 47.2 1.2 48.8 2 49.6 3.1 50 4.2 50 5.2 50 6.3 49.6 7.1 48.8L21.2 34.6C24.1 36.5 27.5 37.5 31.3 37.5 41.6 37.5 50 29.1 50 18.8 50 8.4 41.6 0 31.3 0ZM31.3 31.3C24.4 31.3 18.8 25.6 18.8 18.8 18.8 11.9 24.4 6.3 31.3 6.3 38.1 6.3 43.8 11.9 43.8 18.8 43.8 25.6 38.1 31.3 31.3 31.3Z"></path>
                                </g>
                            </svg><span>Search</span></a>
                    </li>
                    <li class="usermenu dropdown">
                        <a href="#" class="trigger l0 nav-icn nav-dropdown">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="20" height="20" version="1.1" fill="#4A3C31">
                                <desc>navigation arrow</desc>
                                <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                    <path d="M0.1 12.5L9.7 3.1C9.8 3 9.9 3 10 3 10.1 3 10.2 3 10.3 3.1L19.9 12.5C20 12.5 20 12.6 20 12.8 20 12.9 20 13 19.9 13L17 15.9C16.9 16 16.8 16 16.7 16 16.5 16 16.4 16 16.4 15.9L10 9.7 3.6 15.9C3.6 16 3.5 16 3.3 16 3.2 16 3.1 16 3 15.9L0.1 13C0 12.9 0 12.8 0 12.7 0 12.7 0 12.6 0.1 12.5Z"></path>
                                </g>
                            </svg><span>Expand Nav</span></a>
                        <div class="drop-content">
                            <ul>
                                <li>
                                    <a href="/history/" class="t-recent-nav l1 nav-icn None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>recent items icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M25 0C11.2 0 0 11.2 0 25 0 38.8 11.2 50 25 50 38.8 50 50 38.8 50 25 50 11.2 38.8 0 25 0ZM6.3 25C6.3 14.6 14.6 6.3 25 6.3 35.4 6.3 43.8 14.6 43.8 25 43.8 35.4 35.4 43.8 25 43.8 14.6 43.8 6.3 35.4 6.3 25ZM31.8 31.5C32.5 30.5 32.4 29.2 31.6 28.3L27.1 23.8 27.1 12.8C27.1 11.5 26.2 10.4 25 10.4 23.9 10.4 22.9 11.5 22.9 12.8L22.9 25.7 28.8 31.7C29.2 32.1 29.7 32.3 30.2 32.3 30.8 32.3 31.3 32 31.8 31.5Z"></path>
                                            </g>
                                        </svg><span>History</span></a>
                                </li>
                                <li>
                                    <a href="/topics" class="t-topics-link l1 nav-icn None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 55" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>topics icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M25 55L50 41.262 50 13.762 25 0 0 13.762 0 41.262 25 55ZM8.333 37.032L8.333 17.968 25 8.462 41.667 17.968 41.667 37.032 25 46.538 8.333 37.032Z"></path>
                                            </g>
                                        </svg><span>Topics</span></a>
                                </li>
                                <li>
                                    <a href="/tutorials/" class="l1 nav-icn t-tutorials-nav js-toggle-menu-item None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>tutorials icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M15.8 18.2C15.8 18.2 15.9 18.2 16 18.2 16.1 18.2 16.2 18.2 16.4 18.2 16.5 18.2 16.7 18.1 16.9 18 17 17.9 17.1 17.8 17.2 17.7 17.3 17.6 17.4 17.5 17.4 17.4 17.5 17.2 17.6 16.9 17.6 16.7 17.6 16.6 17.6 16.5 17.6 16.4 17.5 16.2 17.5 16.1 17.4 15.9 17.3 15.8 17.2 15.6 17 15.5 16.8 15.3 16.6 15.3 16.4 15.2 16.2 15.2 16 15.2 15.8 15.2 15.7 15.2 15.5 15.3 15.3 15.4 15.2 15.4 15.1 15.5 15 15.7 14.9 15.8 14.8 15.9 14.7 16 14.7 16.1 14.6 16.3 14.6 16.4 14.6 16.5 14.6 16.6 14.6 16.6 14.6 16.7 14.6 16.9 14.6 17 14.6 17.1 14.7 17.3 14.7 17.4 14.8 17.6 15 17.7 15.1 17.9 15.2 18 15.3 18 15.5 18.1 15.5 18.1 15.6 18.2 15.7 18.2 15.7 18.2 15.7 18.2 15.8 18.2L15.8 18.2ZM9.4 11.5C9.5 11.5 9.5 11.5 9.6 11.5 9.7 11.5 9.9 11.5 10 11.5 10.2 11.5 10.3 11.4 10.5 11.3 10.6 11.2 10.8 11.1 10.9 11 10.9 10.9 11 10.8 11.1 10.7 11.2 10.5 11.2 10.2 11.2 10 11.2 9.9 11.2 9.8 11.2 9.7 11.2 9.5 11.1 9.4 11 9.2 10.9 9.1 10.8 8.9 10.6 8.8 10.5 8.7 10.3 8.6 10 8.5 9.9 8.5 9.7 8.5 9.5 8.5 9.3 8.5 9.1 8.6 9 8.7 8.8 8.7 8.7 8.8 8.6 9 8.5 9.1 8.4 9.2 8.4 9.3 8.2 9.5 8.2 9.8 8.2 10 8.2 10.1 8.2 10.2 8.2 10.3 8.2 10.5 8.3 10.6 8.4 10.7 8.5 10.9 8.6 11.1 8.7 11.2 8.9 11.3 9 11.4 9.1 11.4 9.2 11.4 9.3 11.5 9.3 11.5 9.3 11.5 9.4 11.5 9.4 11.5L9.4 11.5ZM3 4.8C3.1 4.8 3.1 4.8 3.2 4.8 3.4 4.8 3.5 4.8 3.7 4.8 3.8 4.8 4 4.7 4.1 4.6 4.3 4.5 4.4 4.4 4.5 4.3 4.6 4.2 4.6 4.1 4.7 4 4.8 3.8 4.8 3.5 4.8 3.3 4.8 3.1 4.8 3 4.8 2.9 4.7 2.8 4.7 2.6 4.6 2.5 4.5 2.3 4.4 2.2 4.2 2.1 4 1.9 3.8 1.9 3.6 1.8 3.5 1.8 3.3 1.8 3.1 1.8 2.9 1.8 2.7 1.9 2.6 2 2.4 2.1 2.3 2.2 2.2 2.3 2.1 2.4 2 2.5 2 2.6 1.8 2.8 1.8 3 1.8 3.3 1.8 3.4 1.8 3.5 1.8 3.6 1.8 3.8 1.9 3.9 2 4 2.1 4.2 2.2 4.4 2.4 4.5 2.5 4.6 2.6 4.7 2.7 4.7 2.8 4.7 2.9 4.8 2.9 4.8 3 4.8 3 4.8 3 4.8L3 4.8ZM13.1 15.2C13.2 15.1 13.2 15.1 13.2 15.1 13.3 14.9 13.4 14.7 13.6 14.5 13.8 14.2 14.1 14 14.4 13.8 14.7 13.6 15.1 13.5 15.5 13.4 15.9 13.4 16.3 13.4 16.7 13.5 17.2 13.5 17.6 13.7 17.9 13.9 18.2 14.1 18.5 14.4 18.7 14.7 18.9 15 19.1 15.3 19.2 15.6 19.3 15.9 19.4 16.1 19.4 16.4 19.4 17 19.3 17.5 19.1 18.1 19 18.3 18.9 18.5 18.7 18.7 18.5 19 18.3 19.2 18 19.4 17.7 19.6 17.3 19.8 16.9 19.9 16.6 20 16.3 20 16 20 15.8 20 15.6 20 15.4 19.9 15.4 19.9 15.4 19.9 15.4 19.9 15.2 19.9 15 19.8 14.9 19.8 14.8 19.7 14.7 19.7 14.6 19.7 14.4 19.6 14.3 19.5 14.1 19.3 13.7 19.1 13.4 18.7 13.2 18.4 13.1 18.1 12.9 17.8 12.9 17.5 12.8 17.3 12.8 17.1 12.8 16.9L3.5 14.9C3.3 14.9 3.1 14.8 3 14.8 2.7 14.7 2.4 14.5 2.1 14.3 1.7 14 1.4 13.7 1.2 13.3 1 13 0.9 12.6 0.8 12.3 0.7 12 0.7 11.7 0.7 11.4 0.7 11 0.8 10.5 1 10.1 1.1 9.8 1.3 9.5 1.6 9.2 1.8 8.9 2.1 8.7 2.4 8.5 2.8 8.3 3.2 8.1 3.6 8.1 3.9 8 4.2 8 4.5 8 4.6 8 4.8 8 4.9 8.1L6.8 8.5C6.8 8.4 6.8 8.4 6.8 8.4 6.9 8.2 7.1 8 7.2 7.8 7.5 7.5 7.7 7.3 8 7.1 8.4 6.9 8.7 6.8 9.1 6.7 9.5 6.7 10 6.7 10.4 6.8 10.8 6.8 11.2 7 11.5 7.2 11.8 7.5 12.1 7.7 12.4 8 12.6 8.3 12.7 8.6 12.8 8.9 12.9 9.2 13 9.4 13 9.7 13 9.7 13 9.8 13 9.8 13.6 9.9 14.2 10.1 14.9 10.2 15 10.2 15 10.2 15.1 10.2 15.3 10.2 15.4 10.2 15.6 10.2 15.8 10.1 16 10 16.2 9.9 16.4 9.8 16.5 9.6 16.6 9.5 16.8 9.2 16.9 8.8 16.9 8.5 16.9 8.3 16.9 8.2 16.8 8 16.8 7.8 16.7 7.7 16.6 7.5 16.5 7.3 16.3 7.2 16.2 7.1 16 7 15.9 6.9 15.8 6.9 15.7 6.9 15.6 6.8 15.5 6.8L6.2 4.8C6.2 5 6 5.2 5.9 5.3 5.7 5.6 5.5 5.8 5.3 6 4.9 6.2 4.5 6.4 4.1 6.5 3.8 6.6 3.5 6.6 3.2 6.6 3 6.6 2.8 6.6 2.7 6.6 2.6 6.6 2.6 6.5 2.6 6.5 2.5 6.5 2.3 6.5 2.1 6.4 1.8 6.3 1.6 6.1 1.3 6 1 5.7 0.7 5.4 0.5 5 0.3 4.7 0.2 4.4 0.1 4.1 0 3.8 0 3.6 0 3.3 0 2.8 0.1 2.2 0.4 1.7 0.5 1.5 0.7 1.3 0.8 1.1 1.1 0.8 1.3 0.6 1.6 0.5 2 0.3 2.3 0.1 2.7 0.1 3.1 0 3.6 0 4 0.1 4.4 0.2 4.8 0.3 5.1 0.5 5.5 0.8 5.7 1 6 1.3 6.2 1.6 6.3 1.9 6.4 2.3 6.5 2.5 6.6 2.7 6.6 3 6.6 3 6.6 3.1 6.6 3.1 9.7 3.8 12.8 4.4 15.9 5.1 16.1 5.1 16.2 5.2 16.4 5.2 16.7 5.3 16.9 5.5 17.2 5.6 17.5 5.9 17.8 6.2 18.1 6.5 18.3 6.8 18.4 7.2 18.6 7.5 18.6 7.9 18.7 8.2 18.7 8.6 18.7 9 18.6 9.4 18.4 9.8 18.3 10.1 18.2 10.3 18 10.6 17.8 10.9 17.5 11.1 17.3 11.3 16.9 11.6 16.5 11.8 16 11.9 15.7 12 15.3 12 15 12 14.8 12 14.7 12 14.5 11.9 13.9 11.8 13.3 11.7 12.6 11.5 12.5 11.7 12.4 11.9 12.3 12 12.1 12.3 11.9 12.5 11.7 12.7 11.3 12.9 10.9 13.1 10.5 13.2 10.2 13.3 9.9 13.3 9.6 13.3 9.4 13.3 9.2 13.3 9 13.2 9 13.2 9 13.2 9 13.2 8.8 13.2 8.7 13.2 8.5 13.1 8.2 13 8 12.8 7.7 12.6 7.4 12.4 7.1 12 6.8 11.7 6.7 11.4 6.6 11.1 6.5 10.8 6.4 10.6 6.4 10.4 6.4 10.2 5.8 10.1 5.2 9.9 4.5 9.8 4.4 9.8 4.4 9.8 4.3 9.8 4.1 9.8 4 9.8 3.8 9.8 3.6 9.9 3.4 10 3.2 10.1 3 10.2 2.9 10.4 2.8 10.5 2.6 10.8 2.5 11.1 2.5 11.5 2.5 11.6 2.5 11.8 2.6 12 2.6 12.1 2.7 12.3 2.8 12.5 2.9 12.6 3.1 12.8 3.2 12.9 3.3 13 3.5 13.1 3.6 13.1 3.7 13.1 3.8 13.2 3.9 13.2L13.1 15.2 13.1 15.2Z"></path>
                                            </g>
                                        </svg><span>Tutorials</span></a>
                                </li>
                                <li class="nav-offers flyout-parent">
                                    <a href="#" class="l1 nav-icn None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>offers icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M35.9 20.6L27 15.5C26.1 15 24.7 15 23.7 15.5L14.9 20.6C13.9 21.1 13.2 22.4 13.2 23.4L13.2 41.4C13.2 42.4 13.9 43.7 14.9 44.2L23.3 49C24.2 49.5 25.6 49.5 26.6 49L35.9 43.6C36.8 43.1 37.6 41.8 37.6 40.8L37.6 23.4C37.6 22.4 36.8 21.1 35.9 20.6L35.9 20.6ZM40 8.2C39.1 7.6 37.6 7.6 36.7 8.2L30.2 11.9C29.3 12.4 29.3 13.2 30.2 13.8L39.1 18.8C40 19.4 40.7 20.6 40.7 21.7L40.7 39C40.7 40.1 41.4 40.5 42.4 40L48.2 36.6C49.1 36.1 49.8 34.9 49.8 33.8L49.8 15.6C49.8 14.6 49.1 13.3 48.2 12.8L40 8.2 40 8.2ZM27 10.1L33.6 6.4C34.5 5.9 34.5 5 33.6 4.5L26.6 0.5C25.6 0 24.2 0 23.3 0.5L16.7 4.2C15.8 4.7 15.8 5.6 16.7 6.1L23.7 10.1C24.7 10.6 26.1 10.6 27 10.1ZM10.1 21.7C10.1 20.6 10.8 19.4 11.7 18.8L20.6 13.8C21.5 13.2 21.5 12.4 20.6 11.9L13.6 7.9C12.7 7.4 11.2 7.4 10.3 7.9L1.6 12.8C0.7 13.3 0 14.6 0 15.6L0 33.8C0 34.9 0.7 36.1 1.6 36.6L8.4 40.5C9.3 41 10.1 40.6 10.1 39.6L10.1 21.7 10.1 21.7Z"></path>
                                            </g>
                                        </svg><span>Offers &amp; Deals</span></a>
                                    <ul class="flyout">
                                        <li><a href="/oreilly-conferences/" class="l2 nav-icn"><span>Conferences</span></a></li>
                                        <li><a href="/oreilly-newsletters/" class="l2 nav-icn"><span>Newsletters</span></a></li>
                                    </ul>
                                </li>
                                <li class="nav-highlights">
                                    <a href="/u/001o000000aVXzJAAW/" class="t-highlights-nav l1 nav-icn None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 35" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>highlights icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M13.325 18.071L8.036 18.071C8.036 11.335 12.36 7.146 22.5 5.594L22.5 0C6.37 1.113 0 10.632 0 22.113 0 29.406 3.477 35 10.403 35 15.545 35 19.578 31.485 19.578 26.184 19.578 21.556 17.211 18.891 13.325 18.071L13.325 18.071ZM40.825 18.071L35.565 18.071C35.565 11.335 39.86 7.146 50 5.594L50 0C33.899 1.113 27.5 10.632 27.5 22.113 27.5 29.406 30.977 35 37.932 35 43.045 35 47.078 31.485 47.078 26.184 47.078 21.556 44.74 18.891 40.825 18.071L40.825 18.071Z"></path>
                                            </g>
                                        </svg><span>Highlights</span></a>
                                </li>
                                <li>
                                    <a href="/u/" class="t-settings-nav l1 js-settings nav-icn None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 53" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>settings icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M44.6 29.6C44.7 28.6 44.8 27.5 44.8 26.5 44.8 25.5 44.7 24.4 44.6 23.4L49.6 19C50 18.8 50.1 18.3 49.9 17.9 48.9 14.7 47.1 11.7 44.9 9.1 44.6 8.8 44.2 8.7 43.8 8.8L37.4 11.1C35.8 9.8 34 8.7 32.1 8L30.9 1.4C30.8 0.9 30.4 0.6 30 0.5 26.7-0.2 23.3-0.2 20 0.5 19.6 0.6 19.2 0.9 19.1 1.4L17.9 8C16 8.7 14.1 9.8 12.6 11.1L6.2 8.8C5.8 8.7 5.4 8.8 5.1 9.1 2.9 11.7 1.1 14.7 0.1 17.9 -0.1 18.3 0 18.8 0.4 19L5.4 23.4C5.3 24.4 5.2 25.5 5.2 26.5 5.2 27.5 5.3 28.6 5.4 29.6L0.4 34C0 34.2-0.1 34.7 0.1 35.1 1.1 38.3 2.9 41.4 5.1 43.9 5.4 44.2 5.8 44.4 6.2 44.2L12.6 42C14.1 43.2 16 44.3 17.9 45L19.1 51.7C19.2 52.1 19.6 52.5 20 52.5 21.6 52.8 23.3 53 25 53 26.7 53 28.4 52.8 30 52.5 30.4 52.5 30.8 52.1 30.9 51.7L32.1 45C34 44.3 35.8 43.2 37.4 42L43.8 44.2C44.2 44.4 44.6 44.2 44.9 43.9 47.1 41.4 48.9 38.3 49.9 35.1 50.1 34.7 50 34.2 49.6 34L44.6 29.6ZM25 36.4C19.6 36.4 15.2 32 15.2 26.5 15.2 21 19.6 16.6 25 16.6 30.4 16.6 34.8 21 34.8 26.5 34.8 32 30.4 36.4 25 36.4Z"></path>
                                            </g>
                                        </svg><span>Settings</span></a>
                                </li>
                                <li><a href="https://www.safaribooksonline.com/public/support" class="l1 no-icon">Support</a></li>
                                <li><a href="/accounts/logout/" class="l1 no-icon">Sign Out</a></li>
                            </ul>
                            <ul class="profile">
                                <li>
                                    <a href="/u/" class="l2 nav-icn None">
                                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 53" width="20" height="20" version="1.1" fill="#4A3C31">
                                            <desc>settings icon</desc>
                                            <g stroke="none" stroke-width="1" fill-rule="evenodd">
                                                <path d="M44.6 29.6C44.7 28.6 44.8 27.5 44.8 26.5 44.8 25.5 44.7 24.4 44.6 23.4L49.6 19C50 18.8 50.1 18.3 49.9 17.9 48.9 14.7 47.1 11.7 44.9 9.1 44.6 8.8 44.2 8.7 43.8 8.8L37.4 11.1C35.8 9.8 34 8.7 32.1 8L30.9 1.4C30.8 0.9 30.4 0.6 30 0.5 26.7-0.2 23.3-0.2 20 0.5 19.6 0.6 19.2 0.9 19.1 1.4L17.9 8C16 8.7 14.1 9.8 12.6 11.1L6.2 8.8C5.8 8.7 5.4 8.8 5.1 9.1 2.9 11.7 1.1 14.7 0.1 17.9 -0.1 18.3 0 18.8 0.4 19L5.4 23.4C5.3 24.4 5.2 25.5 5.2 26.5 5.2 27.5 5.3 28.6 5.4 29.6L0.4 34C0 34.2-0.1 34.7 0.1 35.1 1.1 38.3 2.9 41.4 5.1 43.9 5.4 44.2 5.8 44.4 6.2 44.2L12.6 42C14.1 43.2 16 44.3 17.9 45L19.1 51.7C19.2 52.1 19.6 52.5 20 52.5 21.6 52.8 23.3 53 25 53 26.7 53 28.4 52.8 30 52.5 30.4 52.5 30.8 52.1 30.9 51.7L32.1 45C34 44.3 35.8 43.2 37.4 42L43.8 44.2C44.2 44.4 44.6 44.2 44.9 43.9 47.1 41.4 48.9 38.3 49.9 35.1 50.1 34.7 50 34.2 49.6 34L44.6 29.6ZM25 36.4C19.6 36.4 15.2 32 15.2 26.5 15.2 21 19.6 16.6 25 16.6 30.4 16.6 34.8 21 34.8 26.5 34.8 32 30.4 36.4 25 36.4Z"></path>
                                            </g>
                                        </svg><span>Settings</span></a>
                                </li>
                                <li><a href="https://www.safaribooksonline.com/public/support" class="l2">Support</a></li>
                                <li><a href="/accounts/logout/" class="l2">Sign Out</a></li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </nav>
        </header>
    </div>
    <div id="container" class="application">
        <div class="nav-container clearfix">
        </div>
        <div class="js-toc">
            <div class="sbo-reading-menu sbo-menu-top">
                <section class="sbo-toc-container toc-menu"><a href="#" class="sbo-toc-thumb"><span class="sbo-title ss-list"><h1><div class="visuallyhidden">Table of Contents for </div>
      
      Exploring C++ 11, Second Edition
      
    </h1></span></a>
                    <div class="toc-contents"></div>
                </section>
            </div>
            <div class="interface-controls interface-controls-top">
                <ul class="interface-control-btns js-bitlist js-reader">
                    <li class="js-search-in-archive search-in-archive t-search-in-archive"><a href="#" title="Search in archive" class="js-search-controls search-controls"><span class="icon">Search in book...</span></a>
                        <form class="search-archive-bar js-search-form">
                            <input type="search" name="query" placeholder="Search inside this book..." autocomplete="off">
                        </form>
                        <div class="search-archive-results">
                            <div class="js-sitb-results-region"></div>
                        </div>
                    </li>
                    <li class="queue-control">
                        <button type="button" class="rec-fav ss-queue js-queue js-current-chapter-queue" data-queue-endpoint="/api/v1/book/9781430261933/chapter/9781430261933_Ch63.xhtml" data-for-analytics="9781430261933:9781430261933_Ch63.xhtml" aria-label="Add to Queue"><span>Add to Queue</span></button>
                    </li>
                    <li class="js-font-control-panel font-control-activator"><a href="#" data-push-state="false" id="font-controls" title="Change font size" aria-label="Change font size"><span class="icon">Toggle Font Controls</span></a></li>
                    <li class="dropdown sharing-controls"><a href="#" class="trigger" data-push-state="false" title="Share" aria-label="Share"><i class="fa fa-share"></i></a>
                        <ul class="social-sharing dropdown-menu">
                            <li><a class="twitter share-button t-twitter" target="_blank" aria-label="Share this section on Twitter" title="Share this section on Twitter" href="https://twitter.com/share?url=https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml&amp;text=Exploring%20C%2B%2B%2011%2C%20Second%20Edition&amp;via=safari"><span>Twitter</span></a></li>
                            <li><a class="facebook share-button t-facebook" target="_blank" aria-label="Share this section on Facebook" title="Share this section on Facebook" href="https://www.facebook.com/sharer/sharer.php?u=https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml"><span>Facebook</span></a></li>
                            <li><a class="googleplus share-button t-googleplus" target="_blank" aria-label="Share this secton on Google Plus" title="Share this secton on Google Plus" href="https://plus.google.com/share?url=https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml"><span>Google Plus</span></a></li>
                            <li><a class="email share-button t-email" aria-label="Share this section via email" title="Share this section via email" href="mailto:?subject=Safari: Exploration%2063%3A%20Smart%20Pointers&amp;body=https://www.safaribooksonline.com/library/view/exploring-c-11/9781430261933/9781430261933_Ch63.xhtml%0D%0Afrom Exploring%20C%2B%2B%2011%2C%20Second%20Edition%0D%0A"><span>Email</span></a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <section role="document">
                <div class="t-sbo-prev sbo-prev sbo-nav-top">
                    <a href="/library/view/exploring-c-11/9781430261933/9781430261933_Ch62.xhtml" class="prev nav-link">
                        <span aria-hidden="true" class="pagination-label t-prev-label">Prev</span>
                        <span class="visuallyhidden">Previous Chapter</span>
                        <div class="pagination-title t-prev-title">Exploration 62: Old-Fashioned Arrays</div>
                    </a>
                </div>
                <div class="t-sbo-next sbo-next sbo-nav-top">
                    <a href="/library/view/exploring-c-11/9781430261933/9781430261933_Ch64.xhtml" class="next nav-link">
                        <span aria-hidden="true" class="pagination-label t-next-label">Next</span>
                        <span class="visuallyhidden">Next Chapter</span>
                        <div class="pagination-title t-next-title">Exploration 64: Working with Bits</div>
                    </a>
                </div>
                <div id="sbo-rt-content">
                    <div class="annotator-wrapper">
                        <p class="ChapterNumber">
                            <a id="b9781430261933_63"></a>EXPLORATION 63</p>
                        <p class="chapimage"><img src="/library/view/exploring-c-11/9781430261933/images/frontdot.jpg" alt="image" width="82" height="25" data-mfp-src="/library/view/exploring-c-11/9781430261933/images/frontdot.jpg"></p>
                        <p class="ChapterTitle">Smart Pointers
                            <a id="cXXX.784"></a>
                        </p>
                        <div>
                            <p class="noindent">The std::unique_ptr class template is an example of a so-called <i>smart pointer</i>. A smart pointer behaves much like any other pointer but with extra features and functionality. This Exploration takes a closer look at unique_ptr and other smart pointers.</p>
                            <p id="Sec1" class="Heading1">Revisiting unique_ptr</p>
                            <p class="noindent"><a href="9781430261933_Ch61.xhtml">Exploration 61</a> introduced
                                <a id="cXXX.785"></a>unique_ptr as a way to manage dynamically allocated objects. The unique_ptr class template overloads the dereference (*) and member access (-&gt;) operators and lets you use a unique_ptr object the same way you would use a pointer. At the same time, it extends the behavior of an ordinary pointer, such that when the unique_ptr object is destroyed, it automatically deletes the pointer it holds. That’s why unique_ptr is called a <i>smart pointer—</i>it’s just like an ordinary pointer, only smarter. Using unique_ptr helps ensure that memory is properly managed, even in the face of unexpected exceptions.</p>
                            <p class="indent">When used properly, the key feature of unique_ptr is that exactly one unique_ptr object owns a particular pointer. You can move unique_ptr objects. Each time you do, the target of the move becomes the new owner of the pointer.</p>
                            <p class="indent">You can also force a unique_ptr to give up ownership of its pointer by calling the release() member function. The release() function returns the raw pointer, as displayed in the following:</p>
                            <pre><span class="FontName1">std::unique_ptr&lt;int&gt; ap{new int{42}};</span><br><span class="FontName1">int* ip{ap.release()};</span><br><span class="FontName1">delete ip;</span></pre>
                            <p class="indent">Call the reset member function to tell a unique_ptr to take over a different pointer. The unique_ptr object takes control of the new pointer and deletes its old pointer. With no argument, reset() sets the unique_ptr to a null pointer.</p>
                            <pre><span class="FontName1">std::unique_ptr&lt;int&gt; ap{new int{42}};</span><br><span class="FontName1">ap.reset(new int{10}); // deletes the pointer to 42</span><br><span class="FontName1">ap.reset();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// deletes the pointer to 10</span></pre>
                            <p class="indent">The get() member function retrieves the raw pointer without affecting the unique_ptr’s ownership. The unique_ptr template also overloads the dereference (*) and member (-&gt;) operators, so that they work the way they do with ordinary pointers. These functions do not affect ownership of the pointer.</p>
                            <pre><span class="FontName1">std::unique_ptr&lt;rational&gt; rp{new rational{420, 10}};</span><br><span class="FontName1">int n{rp-&gt;numerator()};</span><br><span class="FontName1">rational r{*rp};</span><br><span class="FontName1">rational *raw_ptr{rp.get()};</span></pre>
                            <p class="indent">When unique_ptr holds a pointer to an array (that is, the template argument is an array type, e.g., unique_ptr&lt;int[]&gt;), it supports the subscript operator instead of * and -&gt;.</p>
                            <p class="indent">In order to enforce its ownership semantics, unique_ptr has a move constructor and move assignment operator but deletes its copy constructor and copy assignment operator. If you use unique_ptr for data members in a class, the compiler implicitly deletes the class’s copy constructor and copy assignment operator.</p>
                            <p class="indent">Thus, using unique_ptr may free you from thinking about your class’s destructor, but you are not excused from thinking about the constructors and assignment operators. This is a minor tweak to the guideline that if you have to deal with one, you must deal with all special members. The compiler’s default behavior is usually correct, but you might want to implement a copy constructor that performs a deep copy or other non-default behavior.</p>
                            <p id="Sec2" class="Heading1">Copyable Smart Pointers</p>
                            <p class="noindent">Sometimes, you don’t want exclusive ownership. There are circumstances when multiple objects will share ownership of a pointer. When no objects own the pointer, the memory is automatically reclaimed. The std::shared_ptr smart-pointer type implements shared ownership.
                                <a id="cXXX.786"></a>
                            </p>
                            <p class="indent">Once you deliver a pointer to a shared_ptr, the shared_ptr object owns that pointer. When the shared_ptr object is destroyed, it will delete the pointer. The difference between shared_ptr and unique_ptr is that you can freely copy and assign shared_ptr objects with normal semantics. Unlike unique_ptr, shared_ptr has a copy constructor and copy assignment operator. The shared_ptr object keeps a reference count, so assignment merely increments the reference count, without having to transfer ownership. When a shared_ptr object is destroyed, it decrements the reference count. When the count reaches zero, the pointer is deleted. Thus, you can make as many copies as you like, store shared_ptr objects in a container, pass them to functions, return them from functions, copy them, move them, assign them, and carry on to your heart’s content. It’s that simple. <a id="_list1" href="#list1">Listing 63-1</a> shows that copying shared_ptr works in ways that don’t work with unique_ptr.</p>
                            <p class="noindent2"><b><i><a href="#_list1" id="list1">Listing 63-1</a></i></b>.&nbsp;&nbsp;Working with <span class="FontName1">shared_ptr</span></p>
                            <pre><span class="FontName1">#include &lt;iostream&gt;</span><br><span class="FontName1">#include &lt;memory&gt;</span><br><span class="FontName1">#include &lt;vector&gt;</span><br>&nbsp;<br><span class="FontName1">class see_me</span><br><span class="FontName1">{</span><br><span class="FontName1">public:</span><br>&nbsp;&nbsp;<span class="FontName1">see_me(int x) : x_{x} { std::cout &lt;&lt;&nbsp;&nbsp;"see_me(" &lt;&lt; x_ &lt;&lt; ")\n"; }</span><br>&nbsp;&nbsp;<span class="FontName1">~see_me()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { std::cout &lt;&lt; "~see_me(" &lt;&lt; x_ &lt;&lt; ")\n"; }</span><br>&nbsp;&nbsp;<span class="FontName1">int value() const&nbsp;&nbsp;&nbsp;&nbsp; { return x_; }</span><br><span class="FontName1">private:</span><br>&nbsp;&nbsp;<span class="FontName1">int x_;</span><br><span class="FontName1">};</span><br>&nbsp;<br><span class="FontName1">std::shared_ptr&lt;see_me&gt; does_this_work(std::shared_ptr&lt;see_me&gt; x)</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp;<span class="FontName1">std::shared_ptr&lt;see_me&gt; y{x};</span><br>&nbsp;&nbsp;<span class="FontName1">return y;</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">int main()</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp;<span class="FontName1">std::shared_ptr&lt;see_me&gt; a{}, b{};</span><br>&nbsp;&nbsp;<span class="FontName1">a = std::make_shared&lt;see_me&gt;(42);</span><br>&nbsp;&nbsp;<span class="FontName1">b = does_this_work(a);</span><br>&nbsp;&nbsp;<span class="FontName1">std::vector&lt;std::shared_ptr&lt;see_me&gt;&gt; v{};</span><br>&nbsp;&nbsp;<span class="FontName1">v.push_back(a);</span><br>&nbsp;&nbsp;<span class="FontName1">v.push_back(b);</span><br><span class="FontName1">}</span></pre>
                            <p class="indent">The best way to create a shared_ptr is to call make_shared. The template argument is the type you want to create, and the function arguments are passed directly to the constructor. Due to implementation details, constructing a new shared_ptr instance any other way is slightly less efficient in space and time.</p>
                            <p class="indent">Using shared_ptr, you can reimplement the program from <a id="_list5" href="#list5">Listing 58-5</a>. The old program used the artifact map to manage the lifetime of all artifacts. Although convenient, there is no reason to tie artifacts to this map, because the map is used only for parsing. In a real program, most of its work lies in the actual building of targets, not parsing the input. All the parsing objects should be freed and long gone by the time the program is building targets.</p>
                            <p class="indent"><b>Rewrite the artifact-lookup portion of <a href="#list5">Listing 58-5</a> to allocate artifact objects dynamically, using shared_ptr throughout to refer to artifact pointers.</b> See <a id="_list2" href="#list2">Listing 63-2</a> for my solution.</p>
                            <p class="noindent2"><b><i><a href="#_list2" id="list2">Listing 63-2</a></i></b>.&nbsp;&nbsp;Using Smart Pointers to Manage Artifacts</p>
                            <pre><span class="FontName1">std::map&lt;std::string, std::shared_ptr&lt;artifact&gt;&gt; artifacts;</span><br>&nbsp;<br><span class="FontName1">std::shared_ptr&lt;artifact&gt;</span><br><span class="FontName1">lookup_artifact(std::string const&amp; name)</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp;<span class="FontName1">std::shared_ptr&lt;artifact&gt; a{artifacts[name]};</span><br>&nbsp;&nbsp;<span class="FontName1">if (a.get() == nullptr)</span><br>&nbsp;&nbsp;<span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">a = std::make_shared&lt;artifact&gt;(name);</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">artifacts[name] = a;</span><br>&nbsp;&nbsp;<span class="FontName1">}</span><br>&nbsp;&nbsp;<span class="FontName1">return a;</span><br><span class="FontName1">}</span></pre>
                            <p class="indent">With a little more care, you could use unique_ptr instead of shared_ptr, but that results in greater changes to the rest of the code. You should always prefer unique_ptr to shared_ptr, due to the overhead of maintaining the reference count. But if you require shared ownership, shared_ptr is your choice. In all cases, there is no reason to use raw pointers instead of a smart pointer.</p>
                            <p id="Sec3" class="Heading1">Smart Arrays
                                <a id="cXXX.787"></a>
                            </p>
                            <p class="noindent">Recall from <a href="9781430261933_Ch61.xhtml">Exploration 61</a> that allocating a single object is completely different from allocating an array of objects. Thus, smart pointers must also distinguish between a smart pointer to a single object and a smart pointer to an array of objects. In the C++ standard, the distinction is well-defined: unique_ptr has separate specializations for scalars and arrays. On the other hand, shared_ptr works only with single objects by default. To work with arrays, you have to provide a second argument to the constructor: std::default_delete&lt;T[]&gt;(). The second argument tells the shared_ptr how to delete its pointer. The standard library provides std::default_delete&lt;T[]&gt; to delete a pointer using delete[]. For example:</p>
                            <pre><span class="FontName1">std::shared_ptr&lt;int&gt; array_ptr{ new int[10], std::default_delete&lt;int[]&gt;{} };</span></pre>
                            <p id="Sec4" class="Heading1">Pimpls
                                <a id="cXXX.788"></a>
                            </p>
                            <p class="noindent">No, that’s not a spelling error. Although programmers have spoken for years about pimples and warts in their programs, often referring to unsightly but unavoidable bits of code, Herb Sutter associated the phrase <i>pointer-to-implementation</i> with these pimples to come up with the <i>pimpl</i> idiom.
                                <a id="cXXX.789"></a>
                            </p>
                            <p class="indent">In short, a pimpl is a class that hides implementation details in an implementation class, and the public interface object holds only a pointer to that implementation object. Instead of forcing the user of your class to allocate and de-allocate objects, manage pointers, and keep track of object lifetimes, you can expose a class that is easier to use. Specifically, the user can treat instances of the class as values, in the manner of int and other built-in types.</p>
                            <p class="indent">The pimpl wrapper manages the lifetime of the pimpl object.
                                <a id="cXXX.790"></a>It typically implements the special member functions: copy and move constructors, copy and move assignment operators, and destructor. It delegates most of its other member functions to the pimpl object. The user of the wrapper never has to be concerned with any of this.</p>
                            <p class="indent">Thus, we will rewrite the artifact class so that it wraps a pimpl—that is, a pointer to an artifact_impl class. The artifact_impl class will do the real work, and artifact will merely forward all functions through its pimpl. The language feature that makes pimpls possible is declaring a class name without providing a definition of the class, as illustrated by the following:</p>
                            <pre><span class="FontName1">class artifact_impl;</span></pre>
                            <p class="indent">This class declaration, often called a <i>forward declaration</i>,
                                <a id="cXXX.791"></a>informs the compiler that artifact_impl is the name of a class. The declaration doesn’t provide the compiler with anything more about the class, so the class type is <i>incomplete</i>.
                                <a id="cXXX.792"></a>You face a number of restrictions on what you can do with an incomplete type. In particular, you cannot define any objects or data members of that type, nor can you use an incomplete class as a function parameter or return type. You cannot refer to any members of an incomplete class. But you can use pointers or references to the type when you define objects, data members, function parameters, and return types. In particular, you can use a pointer to artifact_impl in the artifact class.</p>
                            <p class="indent">A normal class definition is a <i>complete</i> type definition.
                                <a id="cXXX.793"></a>You can mix forward declarations with a class definition of the same class name. A common pattern is for a header, such as artifact.hpp, to declare a forward declaration; a source file then fills in the complete class definition.</p>
                            <p class="indent">The definition of the artifact class, therefore, can have a data member that is a pointer to the artifact_impl class, or even a smart pointer to artifact_impl, even though the compiler knows only that artifact_impl is a class but doesn’t know any details about it. This means the artifact.hpp header file is independent of the implementation of artifact_impl. The implementation details are tucked away in a separate file, and the rest of your program can make use of the artifact class completely insulated from artifact_impl. In large projects, this kind of barrier is tremendously important.</p>
                            <p class="indent">Writing the artifact.hpp header is not difficult. Start with a forward declaration of artifact_impl. In the artifact class, the declarations of the member functions are the same as in the original class. Change the data members to a single pointer to artifact_impl. Finally, overload operator&lt; for two artifact objects. Implement the comparison by comparing names. Read <a id="_list3" href="#list3">Listing 63-3</a> to see one possible implementation of this class.</p>
                            <p class="noindent2"><b><i><a href="#_list3" id="list3">Listing 63-3</a></i></b>.&nbsp;&nbsp;Defining an <span class="FontName1">artifact</span> Pimpl Wrapper Class</p>
                            <pre><span class="FontName1">#ifndef ARTIFACT_HPP_</span><br><span class="FontName1">#define ARTIFACT_HPP_</span><br>&nbsp;<br><span class="FontName1">#include &lt;chrono&gt;</span><br><span class="FontName1">#include &lt;memory&gt;</span><br><span class="FontName1">#include &lt;string&gt;</span><br>&nbsp;<br><span class="FontName1">class artifact_impl;</span><br>&nbsp;<br><span class="FontName1">class artifact</span><br><span class="FontName1">{</span><br><span class="FontName1">public:</span><br>&nbsp;&nbsp;<span class="FontName1">typedef std::chrono::system_clock clock;</span><br>&nbsp;&nbsp;<span class="FontName1">artifact();</span><br>&nbsp;&nbsp;<span class="FontName1">artifact(std::string const&amp; name);</span><br>&nbsp;&nbsp;<span class="FontName1">artifact(artifact const&amp;) = default;</span><br>&nbsp;&nbsp;<span class="FontName1">~artifact() = default;</span><br>&nbsp;&nbsp;<span class="FontName1">artifact&amp; operator=(artifact const&amp;) = default;</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">std::string const&amp; name()&nbsp;&nbsp;&nbsp;&nbsp; const;</span><br>&nbsp;&nbsp;<span class="FontName1">clock::time_point&nbsp;&nbsp;mod_time() const;</span><br>&nbsp;&nbsp;<span class="FontName1">std::string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expand(std::string str) const;</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">void build();</span><br>&nbsp;&nbsp;<span class="FontName1">clock::time_point get_mod_time();</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">void store_variable(std::string const&amp; name, std::string const&amp; value);</span><br>&nbsp;<br><span class="FontName1">private:</span><br>&nbsp;&nbsp;<span class="FontName1">std::shared_ptr&lt;artifact_impl&gt; pimpl_;</span><br><span class="FontName1">};</span><br>&nbsp;<br><span class="FontName1">inline bool operator&lt;(artifact const&amp; a, artifact const&amp; b)</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp;<span class="FontName1">return a.name() &lt; b.name();</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">#endif // ARTIFACT_HPP_
</span></pre>
                            <p class="indent">The header defines the artifact class without any mention of artifact_impl, except for the pimpl_
                                <a id="cXXX.63a1"></a> data member.</p>
                            <p class="indent">The next step is to write the source file, artifact.cpp. This is where the compiler needs the full definition of the artifact_impl class, thus making artifact_impl a <i>complete class</i>, so include the artifact_impl.hpp header. The artifact class doesn’t do much on its own. Instead, it just delegates every action to the artifact_impl class. See the details in <a id="_list4" href="#list4">Listing 63-4</a>.
                                <a id="cXXX.794"></a>
                            </p>
                            <p class="noindent2"><b><i><a href="#_list4" id="list4">Listing 63-4</a></i></b>.&nbsp;&nbsp;Implementing the <span class="FontName1">artifact</span> Class</p>
                            <pre><span class="FontName1">#include "artifact.hpp"</span><br><span class="FontName1">#include "artifact_impl.hpp"</span><br>&nbsp;<br><span class="FontName1">artifact::artifact() : pimpl_{std::make_shared&lt;artifact_impl&gt;()} {}</span><br>&nbsp;<br><span class="FontName1">artifact::artifact(std::string const&amp; name)</span><br><span class="FontName1">: pimpl_(std::make_shared&lt;artifact_impl&gt;(name))</span><br><span class="FontName1">{}</span><br>&nbsp;<br><span class="FontName1">std::string const&amp; artifact::name()</span><br><span class="FontName1">const</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp; <span class="FontName1">return pimpl_-&gt;name();</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">artifact::clock::time_point artifact::mod_time()</span><br><span class="FontName1">const</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp; <span class="FontName1">return pimpl_-&gt;mod_time();</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">std::string artifact::expand(std::string str)</span><br><span class="FontName1">const</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp; <span class="FontName1">return pimpl_-&gt;expand(str);</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">void artifact::build()</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp; <span class="FontName1">pimpl_-&gt;build();</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">artifact::clock::time_point artifact::get_mod_time()</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp; <span class="FontName1">return pimpl_-&gt;get_mod_time();</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">void artifact::store_variable(std::string const&amp; name, std::string const&amp; value)</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">pimpl_-&gt;store_variable(name, value);</span><br><span class="FontName1">}</span></pre>
                            <p class="indent">You define the artifact_impl class in the artifact_impl.hpp header. This class looks nearly identical to the original artifact class. <a href="#list5">Listing 63-5</a> shows the artifact_impl class definition.
                                <a id="cXXX.795"></a>
                            </p>
                            <p class="noindent2"><b><i><a href="#_list5" id="list5">Listing 63-5</a></i></b>.&nbsp;&nbsp;Defining the Artifact Implementation Class</p>
                            <pre><span class="FontName1">#ifndef ARTIFACT_IMPL_HPP_</span><br><span class="FontName1">#define ARTIFACT_IMPL_HPP_</span><br>&nbsp;<br><span class="FontName1">#include &lt;cstdlib&gt;</span><br><span class="FontName1">#include &lt;chrono&gt;</span><br><span class="FontName1">#include &lt;memory&gt;</span><br><span class="FontName1">#include &lt;string&gt;</span><br><span class="FontName1">#include "variables.hpp"</span><br>&nbsp;<br><span class="FontName1">class artifact_impl</span><br><span class="FontName1">{</span><br><span class="FontName1">public:</span><br>&nbsp;&nbsp;<span class="FontName1">typedef std::chrono::system_clock clock;</span><br>&nbsp;&nbsp;<span class="FontName1">artifact_impl();</span><br>&nbsp;&nbsp;<span class="FontName1">artifact_impl(std::string const&amp; name);</span><br>&nbsp;&nbsp;<span class="FontName1">artifact_impl(artifact_impl&amp;&amp;) = default;</span><br>&nbsp;&nbsp;<span class="FontName1">artifact_impl(artifact_impl const&amp;) = delete;</span><br>&nbsp;&nbsp;<span class="FontName1">~artifact_impl() = default;</span><br>&nbsp;&nbsp;<span class="FontName1">artifact_impl&amp; operator=(artifact_impl&amp;&amp;) = default;</span><br>&nbsp;&nbsp;<span class="FontName1">artifact_impl&amp; operator=(artifact_impl&amp;) = delete;</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">std::string const&amp; name()&nbsp;&nbsp;&nbsp;&nbsp; const { return name_; }</span><br>&nbsp;&nbsp;<span class="FontName1">clock::time_point&nbsp;&nbsp;mod_time() const { return mod_time_; }</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">std::string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expand(std::string str) const;</span><br>&nbsp;&nbsp;<span class="FontName1">void&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; build();</span><br>&nbsp;&nbsp;<span class="FontName1">clock::time_point&nbsp;&nbsp;get_mod_time();</span><br>&nbsp;&nbsp;<span class="FontName1">void store_variable(std::string const&amp; name, std::string const&amp; value);</span><br><span class="FontName1">private:</span><br>&nbsp;&nbsp;<span class="FontName1">std::string name_;</span><br>&nbsp;&nbsp;<span class="FontName1">clock::time_point mod_time_;</span><br>&nbsp;&nbsp;<span class="FontName1">std::unique_ptr&lt;variable_map&gt; variables_;</span><br><span class="FontName1">};</span><br>&nbsp;<br><span class="FontName1">#endif // ARTIFACT_IMPL_HPP_</span></pre>
                            <p class="indent">The artifact_impl class is unsurprising. The implementation is just like the old artifact implementation, except the variables_ data member is now managed by unique_ptr instead of explicit code. That means the compiler writes the move constructor, move assignment operator, and destructor for you.</p>
                            <p class="indent">Now it’s time to rewrite the lookup_artifact function yet again. <b>Rewrite <a href="9781430261933_Ch59.xhtml#list4">Listings 59-4</a>, <a href="9781430261933_Ch59.xhtml#list8">59-8</a>, and <a href="#list4">63-4</a> to use the new artifact class.</b> This time, the artifacts map stores artifact objects directly. The dependency_graph class will also have to use artifact instead of artifact*. See <a id="_list6" href="#list6">Listing 63-6</a> for one way to rewrite the program.
                                <a id="cXXX.796"></a>
                            </p>
                            <p class="noindent2"><b><i><a href="#_list6" id="list6">Listing 63-6</a></i></b>.&nbsp;&nbsp;Rewriting the Program to Use the New <span class="FontName1">artifact</span> Value Class</p>
                            <pre><span class="FontName1">#include &lt;chrono&gt;</span><br><span class="FontName1">#include &lt;iostream&gt;</span><br><span class="FontName1">#include &lt;sstream&gt;</span><br><span class="FontName1">#include &lt;string&gt;</span><br>&nbsp;<br><span class="FontName1">#include "artifact.hpp"</span><br><span class="FontName1">#include "depgraph.hpp"&nbsp;&nbsp;// <a href="#list5">Listing 58-5</a></span><br>&nbsp;<br><span class="FontName1">#include "variables.hpp" // <a href="#list6">Listing 59-6</a></span><br>&nbsp;<br>&nbsp;<br><b>void parse_graph(std::istream</b><span class="FontName1">&amp;</span> <b>in, dependency_graph</b><span class="FontName1">&amp;</span> <b>graph)</b><br><span class="FontName1">{</span><br>&nbsp;&nbsp;<b>std::map&lt;std::string, artifact&gt; artifacts{};</b><br>&nbsp;&nbsp;<span class="FontName1">std::string line{};</span><br>&nbsp;&nbsp;<span class="FontName1">while (std::getline(in, line))</span><br>&nbsp;&nbsp;<span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">std::string target_name{}, dependency_name{};</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">std::istringstream stream{line};</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">if (stream &gt;&gt; target_name &gt;&gt; dependency_name)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>artifact target{artifacts[expand(target_name, 0)]};</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">std::string::size_type equal{dependency_name.find('=')};</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">if (equal == std::string::npos)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// It's a dependency specification</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>artifact dependency{artifacts[target.expand(dependency_name)]};</b><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">graph.store_dependency(target, dependency);</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">else</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// It's a target-specific variable</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">target.store_variable(dependency_name.substr(0, equal-1),</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">dependency_name.substr(equal+1));</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">else if (not target_name.empty())</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">std::string::size_type equal{target_name.find('=')};</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">if (equal == std::string::npos)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// Input line has a target with no dependency,</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// so report an error.</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">std::cerr &lt;&lt; "malformed input: target, " &lt;&lt; target_name &lt;&lt;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="FontName1">", must be followed by a dependency name\n";</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">else</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">global_variables[target_name.substr(0, equal)] =</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">target_name.substr(equal+1);</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// else ignore blank lines</span><br>&nbsp;&nbsp;<span class="FontName1">}</span><br><span class="FontName1">}</span><br>&nbsp;<br><span class="FontName1">int main()</span><br><span class="FontName1">{</span><br>&nbsp;&nbsp;<span class="FontName1">dependency_graph graph{};</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">parse_graph(std::cin, graph);</span><br>&nbsp;<br>&nbsp;&nbsp;<span class="FontName1">try {</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// Get the sorted artifacts in reverse order.</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<b>std::vector&lt;artifact&gt; sorted{};</b><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">graph.sort(std::back_inserter(sorted));</span><br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">// Then print the artifacts in the correct order.</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">for (auto it(sorted.rbegin()), end(sorted.rend());</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="FontName1">it != end;</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="FontName1">++it)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>std::cout &lt;&lt; it-&gt;name() &lt;&lt; '\n';</b><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">}</span><br>&nbsp;&nbsp;<span class="FontName1">} catch (std::runtime_error const&amp; ex) {</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">std::cerr &lt;&lt; ex.what() &lt;&lt; '\n';</span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="FontName1">return EXIT_FAILURE;</span><br>&nbsp;&nbsp;<span class="FontName1">}</span><br><span class="FontName1">}</span></pre>
                            <p class="indent">As you can see, the code that uses artifact objects is simpler and easier to read. The complexity of managing pointers is pushed down into the artifact and artifact_impl classes. In this manner, the complexity is kept contained in one place and not spread throughout the application. Because the code that uses artifact is now simpler, it is less likely to contain errors. Because the complexity is localized, it is easier to review and test thoroughly. The cost is a little more development time, to write two classes instead of one, and a little more maintenance effort, because anytime a new function is needed in the artifact public interface, that function must also be added to artifact_impl. In many, many situations, the benefits far outweigh the costs, which is why this idiom is so popular.</p>
                            <p class="indent">The new artifact class is easy to use, because you can use it the same way you use an int. That is, you can copy it, assign it, store it in a container, etc., without concern about the size of an artifact object or the cost of copying it. Instead of treating an artifact as a big, fat object, or as a dangerous pointer, you can treat it as a value.
                                <a id="cXXX.797"></a>Defining a class with <i>value semantics</i> makes it easy to use. Although it was more work to implement, the value artifact is the easiest incarnation to use for writing the application.</p>
                            <p id="Sec5" class="Heading1">Iterators</p>
                            <p class="noindent">Perhaps you’ve noticed the similarity between iterator syntax and pointer syntax. The C++ committee deliberately designed iterators to mimic pointers. Indeed, a pointer meets all the requirements of a random-access iterator, so you can use all the standard algorithms with a C-style array, as follows:
                                <a id="cXXX.798"></a>
                            </p>
                            <pre><span class="FontName1">int data[4];</span><br><span class="FontName1">std::fill(data, data + 4, 42);</span></pre>
                            <p class="indent">Thus, iterators are a form of smart pointer. Iterators are especially smart, because they come in five distinct flavors (see <a href="9781430261933_Ch44.xhtml">Exploration 44</a> for a reminder). Random-access iterators are just like pointers; other kinds of iterators have less functionality, so they are smart by being dumb.</p>
                            <p class="indent">Iterators can be just as dangerous as pointers. In their pure form, iterators are nearly as unchecked, wild, and raw as pointers. After all, iterators do not prevent you from advancing too far, from dereferencing an uninitialized iterator, from comparing iterators that point to different containers, etc. The list of unsafe practices with iterators is quite extensive.</p>
                            <p class="indent">Because these errors result in undefined behavior, a library implementer is free to choose any result for each kind of error. In the interest of performance, most libraries do not implement additional safety checks and push that back on the programmer, who can decide on his or her preference for a safety/performance trade-off.</p>
                            <p class="indent">If the programmer prefers safety to performance, some library implementations offer a debugging version that implements a number of safety checks. The debugging version of the standard library can check that iterators refer to the same container when comparing the iterators and throw an exception if they do not. An iterator is allowed to check that it is valid before honoring the dereference (*) operator. An iterator can ensure that it does not advance past the end of a container.</p>
                            <p class="indent">Thus, iterators are smart pointers, because they can be really, really smart. I highly recommend that you take full advantage of all safety features that your standard library offers. Remove checks one by one only after you have measured the performance of your program and found that one particular check degrades performance significantly, and you have the reviews and tests in place to give you confidence in the less safe code.</p>
                            <p class="indent">This completes your tour of pointers and memory. The next topic gets down into the bits and bytes of C++.</p>
                        </div>
                        <div class="annotator-outer annotator-viewer viewer annotator-hide">
                            <ul class="annotator-widget annotator-listing"></ul>
                        </div>
                        <div class="annotator-modal-wrapper annotator-editor-modal annotator-editor annotator-hide">
                            <div class="annotator-outer editor">
                                <h2 class="title">Highlight</h2>
                                <form class="annotator-widget">
                                    <ul class="annotator-listing">
                                        <li class="annotator-item">
                                            <textarea id="annotator-field-0" placeholder="Add a note using markdown (optional)" class="js-editor" maxlength="750"></textarea>
                                        </li>
                                    </ul>
                                    <div class="annotator-controls">
                                        <a class="link-to-markdown" href="https://daringfireball.net/projects/markdown/basics" target="_blank">?</a>
                                        <ul>
                                            <li class="delete annotator-hide"><a href="#delete" class="annotator-delete-note button positive">Delete Note</a></li>
                                            <li class="save"><a href="#save" class="annotator-save annotator-focus button positive">Save Note</a></li>
                                            <li class="cancel"><a href="#cancel" class="annotator-cancel button">Cancel</a></li>
                                        </ul>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="annotator-modal-wrapper annotator-delete-confirm-modal" style="display: none;">
                            <div class="annotator-outer">
                                <h2 class="title">Highlight</h2>
                                <a class="js-close-delete-confirm annotator-cancel close" href="#close">Close</a>
                                <div class="annotator-widget">
                                    <div class="delete-confirm">
                                        Are you sure you want to permanently delete this note?
                                    </div>
                                    <div class="annotator-controls">
                                        <a href="#cancel" class="annotator-cancel button js-cancel-delete-confirm">No, I changed my mind</a>
                                        <a href="#delete" class="annotator-delete button positive js-delete-confirm">Yes, delete it</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="annotator-adder" style="display: none; top: 2960.69px; left: 200px; width: 260px;">
                            <ul class="adders  expandUp">
                                <li class="copy"><a href="#">Copy</a></li>
                                <li class="add-highlight"><a href="#">Add Highlight</a></li>
                                <li class="add-note"><a href="#">
			
				Add Note
			
		</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="t-sbo-prev sbo-prev sbo-nav-bottom">
                    <a href="/library/view/exploring-c-11/9781430261933/9781430261933_Ch62.xhtml" class="prev nav-link">
                        <span aria-hidden="true" class="pagination-label t-prev-label">Prev</span>
                        <span class="visuallyhidden">Previous Chapter</span>
                        <div class="pagination-title t-prev-title">Exploration 62: Old-Fashioned Arrays</div>
                    </a>
                </div>
                <div class="t-sbo-next sbo-next sbo-nav-bottom">
                    <a href="/library/view/exploring-c-11/9781430261933/9781430261933_Ch64.xhtml" class="next nav-link">
                        <span aria-hidden="true" class="pagination-label t-next-label">Next</span>
                        <span class="visuallyhidden">Next Chapter</span>
                        <div class="pagination-title t-next-title">Exploration 64: Working with Bits</div>
                    </a>
                </div>
            </section>
            <div class="reading-controls-bottom">
                <ul class="interface-controls js-bitlist">
                    <li class="queue-control">
                        <button type="button" class="rec-fav ss-queue js-queue js-current-chapter-queue" data-queue-endpoint="/api/v1/book/9781430261933/chapter/9781430261933_Ch63.xhtml" data-for-analytics="9781430261933:9781430261933_Ch63.xhtml" aria-label="Add to Queue">
                            <span>Add to Queue</span>
                        </button>
                    </li>
                </ul>
            </div>
        </div>
        <section class="sbo-saved-archives"></section>
    </div>
    <footer class="pagefoot t-pagefoot">
        <a href="#" class="icon-up" style="display: none;">
            <div class="visuallyhidden">Back to top</div>
        </a>
        <ul class="js-footer-nav">
            <li><a class="t-recommendations-footer" href="/r/">Recommended</a></li>
            <li><a class="t-queue-footer" href="/s/">Queue</a></li>
            <li><a class="t-recent-footer" href="/history/">History</a></li>
            <li><a class="t-topics-footer" href="/topics?q=*&amp;limit=21">Topics</a></li>
            <li><a class="t-tutorials-footer" href="/tutorials/">Tutorials</a></li>
            <li><a class="t-settings-footer js-settings" href="/u/">Settings</a></li>
            <li><a href="https://www.safaribooksonline.com/blog/">Blog</a></li>
            <li class="full-support"><a href="https://www.safaribooksonline.com/public/support">Support</a></li>
            <li><a href="https://www.safaribooksonline.com/apps/">Get the App</a></li>
            <li><a href="/accounts/logout/">Sign Out</a></li>
        </ul>
        <span class="copyright">© 2017 <a href="https://www.safaribooksonline.com" target="_blank">Safari</a>.</span>
        <a href="/terms/">Terms of Service</a> /
        <a href="/privacy/">Privacy Policy</a>
    </footer>
    <script type="text/javascript">
    window.NREUM || (NREUM = {});
    NREUM.info = {
        "agent": "",
        "applicationTime": 620,
        "transactionName": "YgdaZ0NSW0cEB0RdWltNfkZfUEFdCgofXFBHDVYdR1pQQxZeRl1QQj1aWkU=",
        "applicationID": "3275661",
        "errorBeacon": "bam.nr-data.net",
        "beacon": "bam.nr-data.net",
        "queueTime": 0,
        "licenseKey": "510f1a6865"
    }
    </script>
    <script src="/jsi18n/web/" charset="utf-8"></script>
    <script src="/library/jsi18n/appcache/" charset="utf-8"></script>
    <div class="annotator-notice"></div>
    <div class="font-flyout" style="top: 200.009px; left: 1916px;">
        <div class="font-controls-panel">
            <div class="nightmodes">
                <ul>
                    <li class="day">
                        <a href="#" id="day-mode" title="Day Mode">
                            <i class="fa fa-sun-o"></i>
                            <span>Day Mode</span></a>
                    </li>
                    <li class="cloudy">
                        <a href="#" id="cloudy-mode" title="Cloudy Mode">
                            <i class="fa fa-cloud"></i>
                            <span>Cloud Mode</span>
                        </a>
                    </li>
                    <li class="night">
                        <a href="#" id="night-mode" title="Night Mode">
                            <i class="fa fa-moon-o"></i>
                            <span>Night Mode</span>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="font-resizer resizer">
                <div class="draggable-containment-wrapper">
                    <i class="fa fa-font left"></i>
                    <span class="filler" style="width: 50%;"></span>
                    <div id="js-font-size-draggable" class="draggable ui-widget-content ui-draggable ui-draggable-handle" style="position: relative; left: 80px;"></div>
                    <i class="fa fa-font right"></i>
                </div>
            </div>
            <div class="column-resizer resizer">
                <div class="draggable-containment-wrapper">
                    <i class="fa fa-compress left"></i>
                    <span class="filler" style="width: 50%;"></span>
                    <div id="js-column-size-draggable" class="draggable ui-widget-content ui-draggable ui-draggable-handle" style="position: relative; left: 80px;"></div>
                    <i class="fa fa-expand right"></i>
                </div>
            </div>
            <a id="reset" class="button" href="#">Reset</a>
        </div>
    </div>
</body>
